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 108 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
5 changes: 4 additions & 1 deletion include/core/io/ADC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace core::io {
// The different pins are hardware specific. Forware declarationsto allow
// at compilation time the decision of which pins should be used.
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
enum class Pin;
enum class ADCPeriph;

class ADC {

Expand All @@ -18,7 +19,7 @@ class ADC {
*
* @param[in] pin The pin to setup for ADC
*/
ADC(Pin pin);
ADC(Pin pin, ADCPeriph adcPeriph);

/**
* Reads the current voltage in volts on the ADC
Expand Down Expand Up @@ -46,6 +47,8 @@ class ADC {
protected:
/// The pin the ADC is attached to
Pin pin;
/// The internal ADC being used
ADCPeriph adcPeriph;
};

} // namespace core::io
Expand Down
2 changes: 2 additions & 0 deletions include/core/io/pin.hpp
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace core::io {
* these values.
*/
enum class Pin {
DUMMY = -1, // THIS INTENTIONALLY DOES NOT POINT TO A PIN. Used as a default value, so the default value is no
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
// longer PA_O (a real pin)
PA_0 = 0x00,
PA_1 = 0x01,
PA_2 = 0x02,
Expand Down
26 changes: 25 additions & 1 deletion include/core/io/platform/f3xx/ADCf3xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@

namespace core::io {

enum class ADCPeriph {
ONE
};

class ADCf3xx : public ADC {
public:
/**
* Setup the given pin for ADC usage
*
* @param[in] pin The pin to setup for ADC
*/
ADCf3xx(Pin pin);
ADCf3xx(Pin pin, ADCPeriph adcPeriph);
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved

float read();

Expand All @@ -41,6 +45,17 @@ class ADCf3xx : public ADC {
static uint16_t buffer[MAX_CHANNELS];
static DMA_HandleTypeDef halDMA;

/**
* Bit packed struct to contain the channel along with the ADC peripherals the channel supports
*
* adc1: 1 bit. Support for ADC1 peripheral. 1 for supported, 0 for not supported.
* channel: 5 bits. The STM32 ADC channel value with said supported ADC peripherals
*/
struct Channel_Support {
uint8_t adc1 : 1;
uint8_t channel : 5;
};

/**
* Initialize the HAL ADC handler. This should only have to be run once
*/
Expand All @@ -58,6 +73,15 @@ class ADCf3xx : public ADC {
* was added to the ADC starting at 1
*/
void addChannel(uint8_t rank);

/**
* Check if the channel that is being initialized supports the ADC peripheral that it is being initialized on.
*
* @param periph the ADC peripheral being used
* @param channelStruct the struct of the channel with supports to test
* @return true if channel is supported by the ADC peripheral, false otherwise
*/
static bool checkSupport(ADCPeriph periph, Channel_Support channelStruct);
};

} // namespace core::io
Expand Down
117 changes: 101 additions & 16 deletions include/core/io/platform/f4xx/ADCf4xx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@

namespace core::io {

enum class ADCPeriph {
ONE,
TWO,
THREE
};

class ADCf4xx : public ADC {
public:
/**
* Setup the given pin for ADC usage
*
* @param[in] pin The pin to setup for ADC
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
* @param[in] adcPeriph The ADC peripheral being used
*/
ADCf4xx(Pin pin);
ADCf4xx(Pin pin, ADCPeriph adcPeriph);

float read();

Expand All @@ -25,40 +32,118 @@ class ADCf4xx : public ADC {

private:
// Max number of channels supported by the ADC
static constexpr uint8_t MAX_CHANNELS = 15;
static constexpr uint8_t MAX_CHANNELS = 16;
// Number of supported ADC Peripherals
static constexpr uint8_t NUM_ADCS = 3;
// Positive reference voltage of the ADC. Needs to be updated based on the hardware configuration
static constexpr float VREF_POS = 3.3;
// Max value for a 12 bit ADC reading (2^12 - 1)
static constexpr uint32_t MAX_RAW = 4095;
/// This is static since the STM32F3xx only had a single ADC which
/// supports multiple channels, so I made this one only use a single ADC.
/// The F446re has 3 12 bit ADC's. Currently not able to use the other 2.
/// The ADC will be initialized once then each channel will be added on.
static ADC_HandleTypeDef halADC;
/// Static list of all channels supported by the ADC
static Pin channels[MAX_CHANNELS];
/// Buffer for DMA where each spot represents the value read in from a
/// channel
static uint16_t buffer[MAX_CHANNELS];
static DMA_HandleTypeDef halDMA;
// Flag to indicate if the timer has been initialized
static bool timerInit;
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
// Timer handle for TIM8, used to configure and control the timer instance
static TIM_HandleTypeDef htim8;

/**
* Structure to represent the state of an ADC instance.
*
* This structure holds the configuration and current state for an ADC instance, including the
* HAL handle for the ADC and DMA, channel configurations, and data buffers for readings.
*
* halADC: HAL handle for configuring and controlling the ADC peripheral.
* rank: The ADC channel rank in the sequence (starts at 1).
* isADCInit: Flag to indicate whether the ADC has been initialized.
* channels: Array of pins mapped to ADC channels. Initialized to all Pin::DUMMY.
* The array size is defined by MAX_CHANNELS.
* buffer: Array to store ADC values for each channel, indexed according to the channels array.
* Each entry corresponds to a specific ADC channel.
* halDMA: HAL handle for configuring and controlling DMA for the ADC.
*/
struct ADC_State {
ADC_HandleTypeDef halADC = {0};
uint8_t rank = 1;
bool isADCInit = false;
Pin channels[MAX_CHANNELS] = {Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY,
Pin::DUMMY};
uint16_t buffer[MAX_CHANNELS] = {0};
DMA_HandleTypeDef halDMA = {0};
};

/**
* Initialize the HAL ADC handler. This should only have to be run once
* Bit packed struct to contain the channel along with the ADC peripherals the channel supports
*
* adc1: 1 bit. Support for ADC1 peripheral. 1 for supported, 0 for not supported.
* adc2: 1 bit. Support for ADC2 peripheral. 1 for supported, 0 for not supported.
* adc3: 1 bit. Support for ADC3 peripheral. 1 for supported, 0 for not supported.
* 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;
uint8_t channel : 5;
};

// Array of all ADC peripheral states
static ADC_State adcArray[NUM_ADCS];
// The ADC peripheral state of the current object
ADC_State& adcState;
// The number ADC peripheral which is being used in the current object
uint8_t adcNum;

/**
* Check if the channel that is being initialized supports the ADC peripheral that it is being initialized on.
*
* @param periph the ADC peripheral being used
* @param channelStruct the struct of the channel with supports to test
* @return true if channel is supported by the ADC peripheral, false otherwise
*/
static bool checkSupport(ADCPeriph periph, Channel_Support channelStruct);

/**
* Return the ADC number that is in use
*
* @return The adc number that is being used in this specific object
*/
static uint8_t getADCNum(ADCPeriph periph);

/**
* Initialize the HAL ADC handler
*/
void initADC(uint8_t num_channels);

/**
* Initialize the HAL DMA for the ADC, should only have to be run once
* Initialize the HAL DMA for the ADC
*/
void initDMA();

/**
* Adds an ADC channel to the HAL ADC device.
* Add an ADC channel to the HAL ADC device.
*
* @param rank The "rank" which represents the order in which the channel
* was added to the ADC starting at 1
*/
void addChannel(uint8_t rank);

/**
* Initialize Timer 8 to send Update Events, which the ADC listens for to do a conversion
* aka controls ADC conversion frequency
*/
static void initTimer();
};

} // namespace core::io
Expand Down
6 changes: 3 additions & 3 deletions include/core/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ namespace core::io {
* @param[in] pin The pin to use with the ADC
*/
#ifdef ADC_SUPPORTED
template<Pin pin>
template<Pin pin, ADCPeriph adcPeriph = ADCPeriph::ONE>
mjmagee991 marked this conversation as resolved.
Show resolved Hide resolved
ADC& getADC() {
#ifdef STM32F4xx
static ADCf4xx adc(pin);
static ADCf4xx adc(pin, adcPeriph);
return adc;
#endif
#ifdef STM32F3xx
static ADCf3xx adc(pin);
static ADCf3xx adc(pin, adcPeriph);
return adc;
#endif
}
Expand Down
32 changes: 20 additions & 12 deletions samples/adc/multi_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <core/io/ADC.hpp>
#include <core/io/UART.hpp>
#include <core/manager.hpp>
#include <core/utils/log.hpp>
#include <core/utils/time.hpp>

namespace io = core::io;
Expand All @@ -17,23 +18,30 @@ int main() {

io::UART& uart = io::getUART<io::Pin::UART_TX, io::Pin::UART_RX>(9600);

uart.printf("Starting ADC test\r\n");
// Set up the logger to catch errors in ADC creation
core::log::LOGGER.setUART(&uart);
core::log::LOGGER.setLogLevel(core::log::Logger::LogLevel::INFO);

core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "Starting ADC test");

time::wait(500);

io::ADC& adc0 = io::getADC<io::Pin::PA_0>();
io::ADC& adc1 = io::getADC<io::Pin::PA_1>();
io::ADC& adc0 = io::getADC<io::Pin::PA_0, 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) {
uart.printf("--------------------\r\n");
uart.printf("ADC0 : %d mV\r\n", static_cast<uint32_t>(adc0.read() * 1000));
uart.printf("ADC0: %d%%\r\n", static_cast<uint32_t>(adc0.readPercentage() * 100));
uart.printf("ADC0 raw: %d\r\n\r\n", adc0.readRaw());

uart.printf("ADC1 : %d mV\r\n", static_cast<uint32_t>(adc1.read() * 1000));
uart.printf("ADC1: %d%%\r\n", static_cast<uint32_t>(adc1.readPercentage() * 100));
uart.printf("ADC1 raw: %d\r\n", adc1.readRaw());
uart.printf("--------------------\r\n\r\n");
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------");
core::log::LOGGER.log(
core::log::Logger::LogLevel::INFO, "ADC1 : %d mV", static_cast<uint32_t>(adc0.read() * 1000));
core::log::LOGGER.log(
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(
core::log::Logger::LogLevel::INFO, "ADC1: %d%%", static_cast<uint32_t>(adc1.readPercentage() * 100));
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "ADC1 raw: %d\r\n", adc1.readRaw());
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------\r\n");
time::wait(500);
}
}
19 changes: 13 additions & 6 deletions samples/adc/single_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <core/io/ADC.hpp>
#include <core/io/UART.hpp>
#include <core/manager.hpp>
#include <core/utils/log.hpp>
#include <core/utils/time.hpp>

namespace io = core::io;
Expand All @@ -17,18 +18,24 @@ int main() {

io::UART& uart = io::getUART<io::Pin::UART_TX, io::Pin::UART_RX>(9600);

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

uart.printf("Starting ADC test\r\n");

time::wait(500);

io::ADC& adc0 = io::getADC<io::Pin::PA_0>();
io::ADC& adc0 = io::getADC<io::Pin::PA_0, io::ADCPeriph::ONE>();

while (1) {
uart.printf("--------------------\r\n");
uart.printf("ADC0 : %d mV\r\n", static_cast<uint32_t>(adc0.read() * 1000));
uart.printf("ADC0: %d%%\r\n", static_cast<uint32_t>(adc0.readPercentage() * 100));
uart.printf("ADC0 raw: %d\r\n\r\n", adc0.readRaw());
uart.printf("--------------------\r\n\r\n");
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.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());
tmb5932 marked this conversation as resolved.
Show resolved Hide resolved
core::log::LOGGER.log(core::log::Logger::LogLevel::INFO, "--------------------\r\n");
time::wait(500);
}
}
4 changes: 1 addition & 3 deletions src/core/io/ADC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace core::io {

ADC::ADC(Pin pin) {
this->pin = pin;
}
ADC::ADC(Pin pin, ADCPeriph adcPeriph) : pin(pin), adcPeriph(adcPeriph) {}

} // namespace core::io
Loading
Loading