Files
fmini-1/firmware/hal/fm1_adc.h
T
ClaudeandКирилл Сапфиров c8d571bd22 Felucca 1.6.1
MENU > LARGE keeps one size per knob (#251): each knob shows all its
values in the size its longest value fits, so a value no longer jumps
between sizes while it is turned. No new fonts.

Updates check the package's size on the device: the update entry and the
update loader take only a package whose firmware area is exactly the
FM-1's. Another device's package is refused before anything is erased
(the update screen shows FAILED -15; the loader answers -14).

Second core (beta, PR #247): MENU > SYSTEM > 2ND CORE, OFF by default.
ON (BETA) applies from the next power-on: the second core renders some
of the four parts of each block, bit for bit the one-core sound. A unit
whose second core misreads goes on with one core and sets it back to
OFF. FELUCCA_CPU2=0 builds none of it. Start, mailbox and guards from
X0X (with Melodee's dual-core findings), the split and hardening after
Jangada.

Felucca-Engines: ANALOG, LOFI, TRIO, WHEEL and NOISE, the engine
interface, the shared DSP helpers and their table generator move to
https://github.com/hugelton/Felucca-Engines under the MIT licence,
included as the git submodule firmware/engines. The firmware stays
GPL-3.0-only; clone with --recurse-submodules. The sound is unchanged
(the same golden renders); the engines' own tests run with Felucca's.

Co-authored-by: Кирилл Сапфиров <gospodindilly@gmail.com>
2026-10-17 19:04:28 -03:00

46 lines
1.3 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
/* FM-1 SARADC: PB6 = MASTER pot (ch4),
* PB1 = battery divider (ch3). Polled, 10 bit, from the main loop.
*
* fm1_adc_init() both pins analog inputs, no pulls
* fm1_adc_read(ch) 0..1023, -1 on timeout
*/
#pragma once
#include <stdint.h>
#include "fm1_gpio.h"
#define FM1_ADC_CON (*(volatile uint32_t *)0x13100u)
#define FM1_ADC_RES (*(volatile uint32_t *)0x13104u)
#define FM1_WLA_CON0 (*(volatile uint32_t *)0x11900u)
enum { FM1_ADC_BATT = 3, FM1_ADC_MASTER = 4 };
/* Both are only ever analog inputs: PB1 held low for 8 s would reset the
* chip (isd_config). */
static void fm1_adc_init(void)
{
uint32_t m = (1u << 6) | (1u << 1);
FM1_PR(FM1_PB, FM1_DIE) &= ~m;
FM1_PR(FM1_PB, FM1_PU) &= ~m;
FM1_PR(FM1_PB, FM1_PD) &= ~m;
FM1_PR(FM1_PB, FM1_DIR) |= m;
}
static int32_t fm1_adc_read(uint32_t ch)
{
uint32_t t, v;
FM1_ADC_CON = 0;
if (FM1_WLA_CON0 & (1u << 14))
FM1_WLA_CON0 &= ~(1u << 14);
FM1_ADC_CON = 0xF04Eu | ((ch & 0xFu) << 8);
FM1_ADC_CON |= 0x10u;
FM1_ADC_CON |= 0x40u;
for (t = 0; t < 20000u; t++)
if (FM1_ADC_CON & 0x80u)
break;
v = FM1_ADC_RES & 0x3FFu;
FM1_ADC_CON = 0x40u;
FM1_ADC_CON = 0;
return t == 20000u ? -1 : (int32_t)v;
}