Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FWT-45 adding Multiple Actually Dangerous Commits (Multi ADC Support) #108

Merged
merged 115 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
f7028f6
Added new variable "adcPeriph" to adc class, so you can now choose th…
tmb5932 Sep 21, 2024
ff87ea2
Added new method along with define statements to create a single uint…
tmb5932 Sep 24, 2024
0cd6678
Updated ADC f4 to support multiple ADC's simultaneously (In theory)
tmb5932 Sep 28, 2024
206a267
Fixed where default value was assigned
tmb5932 Sep 28, 2024
ee190f8
fixed misplaced comments
tmb5932 Sep 28, 2024
7cbba52
Altered adc f3 JUST enough so it will compile. Will come back to it.
tmb5932 Sep 28, 2024
05e67ae
Altered adc f3 JUST enough so it will compile. Will come back to it.
tmb5932 Sep 28, 2024
9f9fb81
Applied Formatting Changes During GitHub Build
Sep 28, 2024
65e9968
Single ADC works for all 3. Multi not so much
tmb5932 Sep 28, 2024
621ad09
Clang formatting
tmb5932 Sep 28, 2024
e574c37
Made it initializer list
tmb5932 Oct 3, 2024
e4971e3
Created struct to store each adc state information
tmb5932 Oct 3, 2024
2771124
swapped over to using the struct. Still has old code, just commented out
tmb5932 Oct 3, 2024
72a569d
added dummy pin so that the pin array isnt initialized to all PA_0.
tmb5932 Oct 5, 2024
80fd520
Testing alterations to multiadc sample. will be reverted when im done
tmb5932 Oct 5, 2024
ebcb3ce
added default values to the typedef struct. also am testing using 1 r…
tmb5932 Oct 5, 2024
97d8d79
Trying to make it work...
tmb5932 Oct 5, 2024
bde81b0
Single adc works with single channel... Multi adc works, BUT only if…
tmb5932 Oct 19, 2024
c08692b
MULTI & SINGLE WORK WITH 1 CHANNEL PER ADC
tmb5932 Oct 21, 2024
c9b4dbf
so it will build on github
tmb5932 Oct 21, 2024
ff878a1
Applied Formatting Changes During GitHub Build
Oct 21, 2024
3e1ec95
CubeIDE certified code... Doesnt work. but progress towards DMA Multi…
tmb5932 Oct 29, 2024
e73ce50
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Oct 29, 2024
047f971
Applied Formatting Changes During GitHub Build
Oct 29, 2024
63025d9
SINGLE ADC WORKS!!!
tmb5932 Nov 1, 2024
8a73d05
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 1, 2024
08502cb
Applied Formatting Changes During GitHub Build
Nov 1, 2024
d0fe7d2
MULTI ADC Works!! Need to clean up but...
tmb5932 Nov 1, 2024
4a00fcb
Added logger to print invalid ADC pin errors
tmb5932 Nov 2, 2024
836c4c2
Added log message for hard fault errors, and changed timer period to …
tmb5932 Nov 2, 2024
ef43d5d
Applied Formatting Changes During GitHub Build
Nov 2, 2024
11f81bc
Removed redundant default value
tmb5932 Nov 2, 2024
9964347
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 2, 2024
405190d
added comments in the header and removed commented out code
tmb5932 Nov 2, 2024
5ce1e2d
Applied Formatting Changes During GitHub Build
Nov 2, 2024
1bc3118
Reset sample to main default
tmb5932 Nov 2, 2024
48c0442
removed redundant code, and set priority back to very high, which is …
tmb5932 Nov 2, 2024
6b88e06
added comment in interrupt overrides
tmb5932 Nov 2, 2024
ece892b
Merge branch 'main' of https://github.com/RIT-EVT/EVT-core into featu…
tmb5932 Nov 2, 2024
22c20e3
merges
tmb5932 Nov 2, 2024
e5f15fd
merges
tmb5932 Nov 2, 2024
d490330
Update .gitignore
tmb5932 Nov 2, 2024
206cf4a
Update stm32f3xx.hpp
tmb5932 Nov 2, 2024
f16810a
Update main.cpp
tmb5932 Nov 2, 2024
3e58960
Update Timerf3xx.cpp
tmb5932 Nov 2, 2024
ff6dc60
Update CANf3xx.cpp
tmb5932 Nov 2, 2024
bb24aba
Update PWMf3xx.cpp
tmb5932 Nov 2, 2024
098d4d3
Update SPIf3xx.cpp
tmb5932 Nov 2, 2024
6fafbeb
Update stm32f302x8.cpp
tmb5932 Nov 2, 2024
7f08337
updated comment :)
tmb5932 Nov 4, 2024
dc070c2
Update include/core/io/ADC.hpp
tmb5932 Nov 8, 2024
50c4ff6
removed adc array that just shadows hpp array
tmb5932 Nov 8, 2024
323b112
fixed comments in hpp
tmb5932 Nov 8, 2024
20dcc3f
Update src/core/io/platform/f4xx/ADCf4xx.cpp
tmb5932 Nov 8, 2024
a37a74a
made define into constrexpr
tmb5932 Nov 8, 2024
6af8eea
added comment for dummy pin, changed myPins var name
tmb5932 Nov 8, 2024
4c899fe
merging
tmb5932 Nov 8, 2024
ea1610a
Applied Formatting Changes During GitHub Build
Nov 8, 2024
f228444
updated struct
tmb5932 Nov 8, 2024
85f21c4
added inline & comments
tmb5932 Nov 8, 2024
87af1e7
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 8, 2024
02e7a68
fixed comments and macros
tmb5932 Nov 8, 2024
27784a2
made adcState a local variable
tmb5932 Nov 8, 2024
f4d19db
Applied Formatting Changes During GitHub Build
Nov 8, 2024
ce0582a
added logs to everything fr
tmb5932 Nov 8, 2024
6542fef
changed to local variables
tmb5932 Nov 8, 2024
b7942ae
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 8, 2024
dff10d4
Applied Formatting Changes During GitHub Build
Nov 8, 2024
73b9001
moved interrupts to inside blank namespace and added space in hpp.
tmb5932 Nov 8, 2024
e9f975c
moved interrupts to inside blank namespace and added space in hpp.
tmb5932 Nov 8, 2024
f8a8eb7
added checkSupport to f3hpp
tmb5932 Nov 8, 2024
1d42469
updated f3 adc
tmb5932 Nov 8, 2024
b2c30ad
Applied Formatting Changes During GitHub Build
Nov 8, 2024
5745415
updated member initalization list
tmb5932 Nov 9, 2024
2f3bf06
changed adcState to a reference
tmb5932 Nov 9, 2024
4ff5281
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 9, 2024
5ccb2c3
Applied Formatting Changes During GitHub Build
Nov 9, 2024
546bd04
moved adcNum to initializer list
tmb5932 Nov 9, 2024
2f72f33
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 9, 2024
a2f315c
Applied Formatting Changes During GitHub Build
Nov 9, 2024
b71ccbc
made getADCNum and InitTimer both static, and fixed capitalization on…
tmb5932 Nov 9, 2024
573b5eb
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 9, 2024
9e3d5d7
Applied Formatting Changes During GitHub Build
Nov 9, 2024
ff4ee23
added timer comment
tmb5932 Nov 9, 2024
53183cc
merge
tmb5932 Nov 9, 2024
dd872c5
Applied Formatting Changes During GitHub Build
Nov 9, 2024
c1a7694
changed f3 adc check support to static
tmb5932 Nov 9, 2024
0f819b4
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 9, 2024
c2ff53f
added commetns for new variables in f4adc.hpp
tmb5932 Nov 9, 2024
fa1a291
changed comment
tmb5932 Nov 9, 2024
a965e44
comment alteration that I forgot to change when reading through magee…
tmb5932 Nov 9, 2024
f258d26
fixed spacing and also removed extra \r\n from log statements
tmb5932 Nov 10, 2024
7da0661
removed inline from check support
tmb5932 Nov 10, 2024
7a734f3
removed "_t" from ADC_State
tmb5932 Nov 10, 2024
cbb5205
updated comments in adcf4xx.hpp
tmb5932 Nov 10, 2024
0a31112
no more inline, and added bit packed struct
tmb5932 Nov 10, 2024
ddbc380
clang formatting
tmb5932 Nov 10, 2024
6678459
removed extra stuff
tmb5932 Nov 10, 2024
906bd4e
updated comment placement & added log message to f3
tmb5932 Nov 10, 2024
4131d5c
changed switch to 1 liner, and typecasting channel to uint8_t
tmb5932 Nov 12, 2024
4f52d2f
Merge branch 'main' of https://github.com/RIT-EVT/EVT-core into featu…
tmb5932 Nov 12, 2024
838e7f3
Applied Formatting Changes During GitHub Build
Nov 12, 2024
91c6aba
changed switch to 1 liner, and typecasting channel to uint8_t
tmb5932 Nov 12, 2024
7c1ff1b
Merge remote-tracking branch 'origin/feature/tmb5932/MultiADC' into f…
tmb5932 Nov 12, 2024
c1cc5a1
Applied Formatting Changes During GitHub Build
Nov 12, 2024
5e6e6f1
The giga tester commit. 3 ADC periphs with 3 channels on each
tmb5932 Nov 15, 2024
97206e7
added ADCf4xx:: for all static variables
tmb5932 Nov 15, 2024
ee7fd23
reset sample to normal
tmb5932 Nov 15, 2024
9bb85d5
changed 1 logger message back to uart so people see it if logger isnt…
tmb5932 Nov 16, 2024
4ab700e
Update ADC.hpp
tmb5932 Dec 3, 2024
de2574f
changed 1 logger message back to uart so people see it if logger isnt…
tmb5932 Dec 6, 2024
5487bd0
moved irq handler anon namespace inside the core::io namespace
tmb5932 Dec 6, 2024
d40ab00
moved irq handler anon namespace inside the core::io namespace
tmb5932 Dec 6, 2024
32e5c7c
Applied Formatting Changes During GitHub Build
Dec 6, 2024
203571a
need to merge please github auto formatter.
tmb5932 Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/core/io/platform/f3xx/ADCf3xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ADCf3xx : public ADC {
* channel: 5 bits. The STM32 ADC channel value with said supported ADC peripherals
*/
struct Channel_Support {
uint8_t adc1 : 1;
uint32_t channel : 5;
uint8_t adc1 : 1;
uint8_t channel : 5;
};

/**
Expand Down
8 changes: 4 additions & 4 deletions include/core/io/platform/f4xx/ADCf4xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class ADCf4xx : public ADC {
* channel: 5 bits. The STM32 ADC channel value with said supported ADC peripherals
*/
struct Channel_Support {
uint8_t adc1 : 1;
uint8_t adc2 : 1;
uint8_t adc3 : 1;
uint32_t channel : 5;
uint8_t adc1 : 1;
uint8_t adc2 : 1;
uint8_t adc3 : 1;
uint8_t channel : 5;
};

// Array of all ADC peripheral states
Expand Down
13 changes: 6 additions & 7 deletions samples/adc/multi_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ int main() {

// Set up the logger to catch errors in ADC creation
core::log::LOGGER.setUART(&uart);
core::log::LOGGER.setLogLevel(core::log::Logger::LogLevel::ERROR);
core::log::LOGGER.setLogLevel(core::log::Logger::LogLevel::INFO);

uart.printf("Starting ADC test\r\n");
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "Starting ADC test");
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved

time::wait(500);

io::ADC& adc0 = io::getADC<io::Pin::PA_0, io::ADCPeriph::ONE>();
io::ADC& adc1 = io::getADC<io::Pin::PA_1, io::ADCPeriph::ONE>();
io::ADC& adc1 = io::getADC<io::Pin::PC_4, io::ADCPeriph::ONE>();
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved

while (1) {
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------");
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC0 : %d mV", static_cast<uint32_t>(adc0.read() * 1000));
core::log::Logger::LogLevel::INFO, "ADC1 : %d mV", static_cast<uint32_t>(adc0.read() * 1000));
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC0: %d%%", static_cast<uint32_t>(adc0.readPercentage() * 100));
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "ADC0 raw: %d\r\n", adc0.readRaw());

core::log::Logger::LogLevel::INFO, "ADC1: %d%%", static_cast<uint32_t>(adc0.readPercentage() * 100));
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "ADC1 raw: %d\r\n", adc0.readRaw());
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC1 : %d mV", static_cast<uint32_t>(adc1.read() * 1000));
core::log::LOGGER.log(
Expand Down
50 changes: 18 additions & 32 deletions src/core/io/platform/f3xx/ADCf3xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ADCf3xx::ADCf3xx(Pin pin, ADCPeriph adcPeriph) : ADC(pin, adcPeriph) {

// Maximum number of ADC channels have already been added
if (rank == MAX_CHANNELS) {
log::LOGGER.log(log::Logger::LogLevel::WARNING, "ADC1 ALREADY HAS MAX NUMBER OF CHANNELS!!");
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down Expand Up @@ -135,71 +136,56 @@ void ADCf3xx::addChannel(uint8_t rank) {
GPIOf3xx::gpioStateInit(&gpioInit, myPins, numOfPins, GPIO_MODE_ANALOG, GPIO_NOPULL, GPIO_SPEED_FREQ_HIGH);

ADC_ChannelConfTypeDef adcChannel;
Channel_Support channelStruct = {};
Channel_Support channelStruct;

switch (pin) {
case Pin::PA_0:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_1;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_1)};
break;
case Pin::PA_1:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_2;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_2)};
break;
case Pin::PA_2:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_3;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_3)};
break;
case Pin::PA_3:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_4;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_4)};
break;
case Pin::PA_4:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_5;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_5)};
break;
case Pin::PC_0:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_6;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_6)};
break;
case Pin::PC_1:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_7;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_7)};
break;
case Pin::PC_2:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_8;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_8)};
break;
case Pin::PC_3:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_9;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_9)};
break;
case Pin::PA_6:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_10;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_10)};
break;
case Pin::PB_0:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_11;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_11)};
break;
case Pin::PB_1:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_12;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_12)};
break;
case Pin::PB_13:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_13;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_13)};
break;
case Pin::PB_11:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_14;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_14)};
break;
case Pin::PA_7:
channelStruct.adc1 = 1;
channelStruct.channel = ADC_CHANNEL_15;
channelStruct = {.adc1 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_15)};
break;
default:
// Channel Struct is set to all 0 at initialization, so no need to be set all support bits to 0
channelStruct = {}; // sets all variables to 0
log::LOGGER.log(log::Logger::LogLevel::ERROR, "INVALID PIN 0x%x!!", pin);
break; // Should never get here
}
Expand Down
132 changes: 43 additions & 89 deletions src/core/io/platform/f4xx/ADCf4xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ constexpr uint8_t ADC1_SLOT = 0;
constexpr uint8_t ADC2_SLOT = 1;
constexpr uint8_t ADC3_SLOT = 2;

bool ADCf4xx::timerInit = false;
ADCf4xx::ADC_State core::io::ADCf4xx::adcArray[NUM_ADCS];
bool core::io::ADCf4xx::timerInit = false;
TIM_HandleTypeDef core::io::ADCf4xx::htim8;

ADCf4xx::ADCf4xx(Pin pin, ADCPeriph adcPeriph)
: ADC(pin, adcPeriph), adcState(adcArray[getADCNum(adcPeriph)]), adcNum(getADCNum(adcPeriph)) {
: ADC(pin, adcPeriph), adcState(ADCf4xx::adcArray[getADCNum(adcPeriph)]), adcNum(getADCNum(adcPeriph)) {
if (adcState.rank == MAX_CHANNELS) {
log::LOGGER.log(log::Logger::LogLevel::WARNING, "ADC %d ALREADY HAS MAX PINS!!", (adcNum + 1));
log::LOGGER.log(log::Logger::LogLevel::WARNING, "ADC %d ALREADY HAS MAX NUMBER OF CHANNELS!!", (adcNum + 1));
return;
}

if (timerInit) {
HAL_TIM_Base_DeInit(&htim8); // Stop Timer8 (Trigger Source For ADC's)
timerInit = false;
if (ADCf4xx::timerInit) {
HAL_TIM_Base_DeInit(&ADCf4xx::htim8); // Stop Timer8 (Trigger Source For ADC's)
ADCf4xx::timerInit = false;
}

if (adcState.isADCInit) {
Expand All @@ -78,14 +80,14 @@ ADCf4xx::ADCf4xx(Pin pin, ADCPeriph adcPeriph)
initADC(adcState.rank);
addChannel(adcState.rank);

dmaHandle[adcNum] = &this->adcArray[adcNum].halDMA;
adcHandle[adcNum] = &this->adcArray[adcNum].halADC;
dmaHandle[adcNum] = &this->ADCf4xx::adcArray[adcNum].halDMA;
adcHandle[adcNum] = &this->ADCf4xx::adcArray[adcNum].halADC;

if (!timerInit) {
if (!ADCf4xx::timerInit) {
__HAL_RCC_TIM8_CLK_ENABLE();
initTimer();
HAL_TIM_Base_Start(&htim8); // Start Timer8 (Trigger Source For ADC's)
timerInit = true;
HAL_TIM_Base_Start(&ADCf4xx::htim8); // Start Timer8 (Trigger Source For ADC's)
ADCf4xx::timerInit = true;
}

HAL_ADC_Start_DMA(&adcState.halADC, reinterpret_cast<uint32_t*>(&adcState.buffer[0]), adcState.rank);
Expand Down Expand Up @@ -123,8 +125,8 @@ void ADCf4xx::initADC(uint8_t num_channels) {
halADC->Init.ContinuousConvMode = DISABLE;
halADC->Init.DiscontinuousConvMode = DISABLE;
halADC->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
halADC->Init.ExternalTrigConv =
ADC_EXTERNALTRIGCONV_T8_TRGO; // Sets conversions to be done when timer 8 sends an Update Trigger
// Sets conversions to be done when timer 8 sends an Update Trigger
halADC->Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T8_TRGO;
halADC->Init.DataAlign = ADC_DATAALIGN_RIGHT;
halADC->Init.NbrOfConversion = num_channels;
halADC->Init.DMAContinuousRequests = ENABLE;
Expand Down Expand Up @@ -212,108 +214,60 @@ void ADCf4xx::addChannel(uint8_t rank) {
GPIOf4xx::gpioStateInit(&gpioInit, pins, numOfPins, GPIO_MODE_ANALOG, GPIO_NOPULL, GPIO_SPEED_FREQ_HIGH);

ADC_ChannelConfTypeDef adcChannel;
Channel_Support channelStruct = {}; // Create struct and set all values to 0
Channel_Support channelStruct;
// Combines the ADC channel with the ADC peripherals it supports into a struct, avoiding having multi-layered switch
// statements
switch (pin) {
case Pin::PA_0:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_0;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_0)};
break;
case Pin::PA_1:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_1;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_1)};
break;
case Pin::PA_2:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_2;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_2)};
break;
case Pin::PA_3:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_3;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_3)};
break;
case Pin::PA_4:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_4;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_4)};
break;
case Pin::PA_5:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_5;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_5)};
break;
case Pin::PA_6:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_6;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_6)};
break;
case Pin::PA_7:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_7;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_7)};
break;
case Pin::PB_0:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_8;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_8)};
break;
case Pin::PB_1:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_9;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_9)};
break;
case Pin::PC_0:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_10;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_10)};
break;
case Pin::PC_1:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_11;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_11)};
break;
case Pin::PC_2:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_12;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_12)};
break;
case Pin::PC_3:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 1;
channelStruct.channel = ADC_CHANNEL_13;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 1, .channel = static_cast<uint8_t>(ADC_CHANNEL_13)};
break;
case Pin::PC_4:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_14;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_14)};
break;
case Pin::PC_5:
channelStruct.adc1 = 1;
channelStruct.adc2 = 1;
channelStruct.adc3 = 0;
channelStruct.channel = ADC_CHANNEL_15;
channelStruct = {.adc1 = 1, .adc2 = 1, .adc3 = 0, .channel = static_cast<uint8_t>(ADC_CHANNEL_15)};
break;
default:
// Channel Struct is set to all 0 at initialization, so no need to be set all support bits to 0
channelStruct = {}; // sets all values to 0
log::LOGGER.log(log::Logger::LogLevel::ERROR, "INVALID PIN 0x%x!!", pin);
break; // Should never get here
}
Expand Down Expand Up @@ -367,20 +321,20 @@ void ADCf4xx::initTimer() {
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};

htim8.Instance = TIM8;
htim8.Init.Prescaler = 0;
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
htim8.Init.Period = (SystemCoreClock / 1000) - 1;
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim8.Init.RepetitionCounter = 0;
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
HAL_TIM_Base_Init(&htim8);
ADCf4xx::htim8.Instance = TIM8;
mjmagee991 marked this conversation as resolved.
Show resolved Hide resolved
ADCf4xx::htim8.Init.Prescaler = 0;
ADCf4xx::htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
ADCf4xx::htim8.Init.Period = (SystemCoreClock / 1000) - 1;
ADCf4xx::htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
ADCf4xx::htim8.Init.RepetitionCounter = 0;
ADCf4xx::htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
HAL_TIM_Base_Init(&ADCf4xx::htim8);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig);
HAL_TIM_ConfigClockSource(&ADCf4xx::htim8, &sClockSourceConfig);

sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig);
HAL_TIMEx_MasterConfigSynchronization(&ADCf4xx::htim8, &sMasterConfig);
}

} // namespace core::io
Loading