diff options
| author | Selene ToyKeeper | 2023-11-30 09:19:45 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-30 09:19:45 -0700 |
| commit | f745e12c3bc48d8fe544893871191086cf3cccc9 (patch) | |
| tree | 0e7f6c2c5f362719ac4efad9d5c2365f3ed3c159 /arch/avr32dd20.h | |
| parent | added md5sum to build-all.sh output per target (diff) | |
| parent | eliminated direct CCP register access from arch/attiny1616 (diff) | |
| download | anduril-f745e12c3bc48d8fe544893871191086cf3cccc9.tar.gz anduril-f745e12c3bc48d8fe544893871191086cf3cccc9.tar.bz2 anduril-f745e12c3bc48d8fe544893871191086cf3cccc9.zip | |
Merge branch 'avr32dd20-devkit' into trunk
Added support for AVR DD MCUs, particularly avr32dd20. Also did a bunch
of refactoring for how MCU support works, cleaned up the ADC code,
switched to consistent internal formats for voltage and temperature,
fixed the FW3X, and some other little things.
* avr32dd20-devkit: (28 commits)
eliminated direct CCP register access from arch/attiny1616
made the avr32dd20 flashing script more universal
added a build target for FW3X with manually-fixed RGB aux wiring
prevent future issues like the FW3X had
fixed FW3X thermal regulation
fixed incorrect temperature history for a few seconds after waking
fsm/adc: removed dead code
FW3X: fixed external temperature sensor
FW3X: multiple upgrades...
fw3x: fixed swapped red+blue, fixed battery measurements, added police color strobe
fixed ADC on sp10-pro
fixed ADC on attiny85 and related builds
fixed ADC on attiny1634 and related builds
more ADC / DAC / MCU progress...
avr32dd20-devkit: make the defaults a bit more dev friendly (realtime voltage colors, and no simple UI by default)
ADC voltage: battcheck 3 digits, fixed t1616, switched back to 8-bit internal volt unit
got ADC voltage+temp working on avrdd... but broke all other builds/MCUs
1.55V AA battery should not show as "white" voltage color, only purple
started refactoring fsm/adc.*, but need a checkpoint before continuing
added dac-scale.py: short script to calculate avrdd DAC+Vref values from level_calc.py ramp data
...
Diffstat (limited to 'arch/avr32dd20.h')
| -rw-r--r-- | arch/avr32dd20.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/arch/avr32dd20.h b/arch/avr32dd20.h new file mode 100644 index 0000000..09b4096 --- /dev/null +++ b/arch/avr32dd20.h @@ -0,0 +1,115 @@ +// arch/avr32dd20.h: avr32dd20 support header +// Copyright (C) 2023 Selene ToyKeeper +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +////////// clock speed / delay stuff ////////// + +#define F_CPU 12000000UL +#define BOGOMIPS (F_CPU/3800) +#define DELAY_ZERO_TIME 1020 + +inline void mcu_clock_speed(); + +///// clock dividers +// this should work, but needs further validation +inline void clock_prescale_set(uint8_t n); + +// TODO: allow hwdef to define a base clock speed, +// and adjust these values accordingly +typedef enum +{ + // Actual clock is 12 MHz + clock_div_1 = (0), // 12 MHz + clock_div_2 = (CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm), // 6 MHz + clock_div_4 = (CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm), // 3 MHz + clock_div_8 = (CLKCTRL_PDIV_8X_gc | CLKCTRL_PEN_bm), // 1.5 MHz + clock_div_16 = (CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm), // 0.75 MHz + clock_div_32 = (CLKCTRL_PDIV_32X_gc | CLKCTRL_PEN_bm), // 375 kHz + clock_div_64 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 187.5 kHz +} clock_div_t; + + +////////// DAC controls ////////// + +// main LED outputs +#define DAC_LVL DAC0_DATA // 0 to 1023, for 0V to Vref +#define DAC_VREF VREF_DAC0REF // 1.024V, 2.048V, 4.096V, or 2.5V + +// Vref values (suitable for DAC and ADC0) +#define V10 VREF_REFSEL_1V024_gc +#define V20 VREF_REFSEL_2V048_gc +#define V25 VREF_REFSEL_2V500_gc +#define V40 VREF_REFSEL_4V096_gc + + +////////// ADC voltage / temperature ////////// + +#define hwdef_set_admux_therm mcu_set_admux_therm +inline void mcu_set_admux_therm(); + +#define hwdef_set_admux_voltage mcu_set_admux_voltage +inline void mcu_set_admux_voltage(); + +inline void mcu_adc_sleep_mode(); + +inline void mcu_adc_start_measurement(); + +//#define mcu_adc_on hwdef_set_admux_voltage +//void mcu_adc_on(); + +inline void mcu_adc_off(); + +#define ADC_vect ADC0_RESRDY_vect +inline void mcu_adc_vect_clear(); + +// both readings are left-aligned +inline uint16_t mcu_adc_result(); + +// read ADC differently for temperature and voltage +//#define MCU_ADC_RESULT_PER_TYPE +//inline uint16_t mcu_adc_result_temp(); +//inline uint16_t mcu_adc_result_volts(); + +// return Volts * 40, range 0 to 6.375V +#define voltage_raw2cooked mcu_vdd_raw2cooked +inline uint8_t mcu_vdd_raw2cooked(uint16_t measurement); + +// return (temp in Kelvin << 6) +#define temp_raw2cooked mcu_temp_raw2cooked +inline uint16_t mcu_temp_raw2cooked(uint16_t measurement); + +inline uint8_t mcu_adc_lsb(); + + +////////// WDT ////////// + +inline void mcu_wdt_active(); + +inline void mcu_wdt_standby(); + +inline void mcu_wdt_stop(); + +#define WDT_vect RTC_PIT_vect +inline void mcu_wdt_vect_clear(); + + +////////// PCINT - pin change interrupt (e-switch) ////////// + +// set these in hwdef +//#define SWITCH_PORT VPORTD.IN +//#define SWITCH_VECT PORTD_PORT_vect + +inline void mcu_switch_vect_clear(); + +inline void mcu_pcint_on(); + +inline void mcu_pcint_off(); + + +////////// misc ////////// + +void reboot(); + +inline void prevent_reboot_loop(); + |
