summaryrefslogtreecommitdiff
path: root/adc
diff options
context:
space:
mode:
Diffstat (limited to 'adc')
-rw-r--r--adc/SConscript30
-rw-r--r--adc/adc.h41
-rw-r--r--adc/stm32_adc.h (renamed from adc/adc_f3.h)55
3 files changed, 68 insertions, 58 deletions
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;
+};