Compare commits

...

2 Commits

Author SHA1 Message Date
loooph 21e0c3a7d6 ignoring ccls due to local paths 2021-08-23 19:57:37 +02:00
loooph 1f49fb551f Trying to adapt from f4 to f3 DAC 2021-08-23 19:56:36 +02:00
4 changed files with 28 additions and 53 deletions

37
.ccls
View File

@ -1,29 +1,20 @@
clang
%c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega32u4
%cpp -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega32u4
%c -Wimplicit-function-declaration -Wmissing-prototypes -Wstrict-prototypes -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
%cpp -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -Wextra -Wredundant-decls -Wshadow -fno-common -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
-I/home/loooph/synth/include
-I/home/loooph/synth/src
-I/home/loooph/.platformio/packages/framework-arduino-avr/cores/arduino
-I/home/loooph/.platformio/packages/framework-arduino-avr/variants/micro
-I/home/loooph/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src
-I/home/loooph/.platformio/packages/framework-arduino-avr/libraries/HID/src
-I/home/loooph/.platformio/packages/framework-arduino-avr/libraries/SPI/src
-I/home/loooph/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src
-I/home/loooph/.platformio/packages/framework-arduino-avr/libraries/Wire/src
-I/home/loooph/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/include-fixed
-I/home/loooph/.platformio/packages/toolchain-atmelavr/lib/gcc/avr/5.4.0/include
-I/home/loooph/.platformio/packages/toolchain-atmelavr/avr/include
-I/home/loooph/projects/synth/include
-I/home/loooph/projects/synth/src
-I/home/loooph/.platformio/packages/framework-libopencm3
-I/home/loooph/.platformio/packages/framework-libopencm3/include
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include/c++/7.2.1
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include/c++/7.2.1/arm-none-eabi
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/lib/gcc/arm-none-eabi/7.2.1/include-fixed
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/lib/gcc/arm-none-eabi/7.2.1/include
-I/home/loooph/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include
-I/home/loooph/.platformio/packages/tool-unity
-DPLATFORMIO=50101
-DARDUINO_AVR_MICRO
-DF_CPU=16000000L
-DARDUINO_ARCH_AVR
-DARDUINO=10808
-DUSB_VID=0x2341
-DUSB_PID=0x8037
-DUSB_PRODUCT="Arduino Micro"
-DUSB_MANUFACTURER="Arduino"
-D__AVR_ATmega32U4__
-DSTM32F302x8
-DSTM32F3
-DF_CPU=72000000L

3
.gitignore vendored
View File

@ -32,3 +32,6 @@
*.out
*.app
.pio
.ccls-cache
.ccls

View File

@ -1,19 +0,0 @@
# README
Console on PA2 (tx only) 115200@8n1
* Prints the ADC value on PA0 (adc channel 0) on the console
* Echos half that ADC value out to DAC channel 2 on PA5
* Prints the ADC value of PA1 (adc channel 1) to the console.
Recommended wiring:
* pot or any resistor ladder to PA0
* jumper from PA5 to PA1
example output:
...
tick: 228: adc0= 3950, target adc1=1975, adc1=1979
tick: 229: adc0= 3949, target adc1=1974, adc1=1978
tick: 230: adc0= 3950, target adc1=1975, adc1=1979
tick: 231: adc0= 3949, target adc1=1974, adc1=1978
...

View File

@ -36,17 +36,17 @@ int _write(int file, char *ptr, int len);
static void clock_setup(void)
{
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
rcc_clock_setup_hsi(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]);
/* Enable GPIOD clock for LED & USARTs. */
rcc_periph_clock_enable(RCC_GPIOD);
rcc_periph_clock_enable(RCC_GPIOA);
/* Enable clocks for USART2 and dac */
rcc_periph_clock_enable(RCC_USART2);
rcc_periph_clock_enable(RCC_DAC);
rcc_periph_clock_enable(RCC_DAC1);
/* And ADC*/
rcc_periph_clock_enable(RCC_ADC1);
rcc_periph_clock_enable(RCC_ADC12);
}
static void usart_setup(void)
@ -99,8 +99,8 @@ static void adc_setup(void)
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
adc_power_off(ADC1);
adc_disable_scan_mode(ADC1);
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_3CYC);
adc_set_clk_prescale(ADC1, ADC_CCR_CKMODE_DIV2);
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_61DOT5CYC);
adc_power_on(ADC1);
@ -109,10 +109,10 @@ static void adc_setup(void)
static void dac_setup(void)
{
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
dac_disable(DAC1, DAC_CHANNEL2);
dac_disable_waveform_generation(DAC1, DAC_CHANNEL2);
dac_enable(DAC1, DAC_CHANNEL2);
dac_set_trigger_source(DAC1, DAC_CR_TSEL2_SW);
dac_disable(CHANNEL_1);
dac_disable_waveform_generation(CHANNEL_1);
dac_enable(CHANNEL_1);
dac_set_trigger_source(DAC_CR_TSEL2_SW);
}
static uint16_t read_adc_naiive(uint8_t channel)
@ -143,8 +143,8 @@ int main(void)
while (1) {
uint16_t input_adc0 = read_adc_naiive(0);
uint16_t target = input_adc0 / 2;
dac_load_data_buffer_single(DAC1, target, DAC_ALIGN_RIGHT12, DAC_CHANNEL2);
dac_software_trigger(DAC1, DAC_CHANNEL2);
dac_load_data_buffer_single(target, RIGHT12, CHANNEL_2);
dac_software_trigger(CHANNEL_1);
uint16_t input_adc1 = read_adc_naiive(1);
printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n",
j++, input_adc0, target, input_adc1);