diff options
author | Karl Palsson <karlp@tweak.net.au> | 2022-05-04 00:41:45 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-07-27 23:03:11 +0200 |
commit | b5cd432df8f336c90d530b5d55fda7f2c25472c2 (patch) | |
tree | 8f1cbda9f677e6e97676649de7c6e9e00e201ab7 | |
parent | c40eb0b2d6966760899d1d0c2743770ea130ff09 (diff) |
adc: convert to new style
Converted the old STM32 headers to new style and copied offsets to
platform data.
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | SConscript | 1 | ||||
-rw-r--r-- | adc/SConscript | 30 | ||||
-rw-r--r-- | adc/adc.h | 41 | ||||
-rw-r--r-- | adc/stm32_adc.h (renamed from adc/adc_f3.h) | 55 | ||||
-rw-r--r-- | platforms/stm32/f1.yaml | 11 | ||||
-rw-r--r-- | platforms/stm32/f3.yaml | 20 | ||||
-rw-r--r-- | platforms/stm32/f7.yaml | 11 | ||||
-rw-r--r-- | platforms/stm32/wb.yaml | 8 |
9 files changed, 120 insertions, 58 deletions
@@ -6,6 +6,7 @@ docs # Generated source files: ld_scripts/generated.ld +adc/adc.h dma/dma.h exti/exti.h gpio/gpio.h @@ -7,6 +7,7 @@ env.SConscript('ld_scripts/SConscript') env.Append( LIB_SOURCES = [ + env.SConscript('adc/SConscript'), env.SConscript('dma/SConscript'), env.SConscript('exti/SConscript'), env.SConscript('gpio/SConscript'), diff --git a/adc/SConscript b/adc/SConscript new file mode 100644 index 0000000..ae2fd2b --- /dev/null +++ b/adc/SConscript @@ -0,0 +1,30 @@ +Import('env') + +headers = [] +instances = [] +sources = [] +aliases = {} +type_aliases = {} + +periph = env['PLATFORM_SPEC'].get('periph', {}) + +if 'stm32_adc' in periph: + headers.append('stm32_adc.h') + for name, data in periph['stm32_adc'].items(): + if name.find("COMMON") > 0: + instances.append({ + 'type': 'STM32_ADC_COMMON_t<STM32_ADC_COMMON_reg_%s_t>' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + else: + instances.append({ + 'type': 'STM32_ADC_t<STM32_ADC_reg_%s_t>' % data['type'], + 'name': name, + 'args': [data['offset']], + }) + + +env.Jinja2('adc.h', '../templates/periph_instances.h.j2', headers = headers, instances = instances, aliases = aliases, type_aliases = type_aliases) + +Return('sources') diff --git a/adc/adc.h b/adc/adc.h deleted file mode 100644 index 01a2293..0000000 --- a/adc/adc.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef ADC_H -#define ADC_H - -#include <stdint.h> - -struct ADC_t { - volatile uint32_t SR; - volatile uint32_t CR1; - volatile uint32_t CR2; - volatile uint32_t SMPR1; - volatile uint32_t SMPR2; - volatile uint32_t JOFR1; - volatile uint32_t JOFR2; - volatile uint32_t JOFR3; - volatile uint32_t JOFR4; - volatile uint32_t HTR; - volatile uint32_t LTR; - volatile uint32_t SQR1; - volatile uint32_t SQR2; - volatile uint32_t SQR3; - volatile uint32_t JSQR; - volatile uint32_t JDR1; - volatile uint32_t JDR2; - volatile uint32_t JDR3; - volatile uint32_t JDR4; - volatile uint32_t DR; -}; - -#if defined(STM32F1) -static ADC_t& ADC1 = *(ADC_t*)0x40012400; -static ADC_t& ADC2 = *(ADC_t*)0x40012800; -static ADC_t& ADC3 = *(ADC_t*)0x40013c00; -#elif defined(STM32F4) - -#elif defined(STM32F7) -static ADC_t& ADC1 = *(ADC_t*)0x40012000; -static ADC_t& ADC2 = *(ADC_t*)0x40012100; -static ADC_t& ADC3 = *(ADC_t*)0x40012200; -#endif - -#endif diff --git a/adc/adc_f3.h b/adc/stm32_adc.h index a225ebf..6216581 100644 --- a/adc/adc_f3.h +++ b/adc/stm32_adc.h @@ -1,9 +1,32 @@ -#ifndef ADC_F3_H -#define ADC_F3_H +#pragma once -#include <stdint.h> +#include <mmio/mmio.h> -struct ADC_t { +struct STM32_ADC_reg_v1_t { + volatile uint32_t SR; + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t SMPR1; + volatile uint32_t SMPR2; + volatile uint32_t JOFR1; + volatile uint32_t JOFR2; + volatile uint32_t JOFR3; + volatile uint32_t JOFR4; + volatile uint32_t HTR; + volatile uint32_t LTR; + volatile uint32_t SQR1; + volatile uint32_t SQR2; + volatile uint32_t SQR3; + volatile uint32_t JSQR; + volatile uint32_t JDR1; + volatile uint32_t JDR2; + volatile uint32_t JDR3; + volatile uint32_t JDR4; + volatile uint32_t DR; +}; + + +struct STM32_ADC_reg_v2_t { volatile uint32_t ISR; volatile uint32_t IER; volatile uint32_t CR; @@ -41,22 +64,20 @@ struct ADC_t { volatile uint32_t CALFACT; }; -struct ADC_COMMON_t { +struct STM32_ADC_COMMON_reg_v2_t { volatile uint32_t CSR; uint32_t _reserved1; volatile uint32_t CCR; }; -#if defined(STM32F3) -static ADC_t& ADC1 = *(ADC_t*)0x50000000; -static ADC_t& ADC2 = *(ADC_t*)0x50000100; -static ADC_t& ADC3 = *(ADC_t*)0x50000400; -static ADC_t& ADC4 = *(ADC_t*)0x50000500; -static ADC_COMMON_t& ADC_COMMON1 = *(ADC_COMMON_t*)0x50000300; -static ADC_COMMON_t& ADC_COMMON3 = *(ADC_COMMON_t*)0x50000700; -#elif defined(STM32WB) -static ADC_t& ADC1 = *(ADC_t*)0x50040000; -static ADC_COMMON_t& ADC_COMMON1 = *(ADC_COMMON_t*)0x50040300; -#endif +template <typename T> +class STM32_ADC_t : public mmio_ptr<T> { + public: + using mmio_ptr<T>::ptr; +}; -#endif +template <typename T> +class STM32_ADC_COMMON_t : public mmio_ptr<T> { + public: + using mmio_ptr<T>::ptr; +}; diff --git a/platforms/stm32/f1.yaml b/platforms/stm32/f1.yaml index 7e6919d..e4806b9 100644 --- a/platforms/stm32/f1.yaml +++ b/platforms/stm32/f1.yaml @@ -1,5 +1,16 @@ # This is incomplete, just preserving register addresses! - periph: + stm32_adc: + ADC1: + type: v1 + offset: 0x40012400 + ADC2: + type: v1 + offset: 0x40012800 + ADC3: + type: v1 + offset: 0x40013c00 + stm32_flash: FLASH: type: f1 diff --git a/platforms/stm32/f3.yaml b/platforms/stm32/f3.yaml index 6586a7d..03f2498 100644 --- a/platforms/stm32/f3.yaml +++ b/platforms/stm32/f3.yaml @@ -67,6 +67,26 @@ origin: 0x10000000 periph: + stm32_adc: + ADC1: + type: v2 + offset: 0x50000000 + ADC2: + type: v2 + offset: 0x50000100 + ADC3: + type: v2 + offset: 0x50000400 + ADC4: + type: v2 + offset: 0x50000500 + ADC_COMMON1: + type: v2 + offset: 0x50000300 + ADC_COMMON3: + type: v2 + offset: 0x50000700 + stm32_dma: DMA1: type: v1 diff --git a/platforms/stm32/f7.yaml b/platforms/stm32/f7.yaml index 82f6520..e54247f 100644 --- a/platforms/stm32/f7.yaml +++ b/platforms/stm32/f7.yaml @@ -18,6 +18,17 @@ size: 320k periph: + stm32_adc: + ADC1: + type: v1 + offset: 0x40012000 + ADC2: + type: v1 + offset: 0x40012100 + ADC3: + type: v1 + offset: 0x40012200 + stm32_flash: FLASH: type: f4 diff --git a/platforms/stm32/wb.yaml b/platforms/stm32/wb.yaml index e4cf2bb..241c467 100644 --- a/platforms/stm32/wb.yaml +++ b/platforms/stm32/wb.yaml @@ -28,6 +28,14 @@ size: 10k periph: + stm32_adc: + ADC1: + type: v2 + offset: 0x50040000 + ADC_COMMON1: + type: v2 + offset: 0x50040300 + stm32_dma: DMA1: type: v1 |