add Chapter12
This commit is contained in:
18
Chapter12/cpp_hal/hal/adc/inc/adc.hpp
Normal file
18
Chapter12/cpp_hal/hal/adc/inc/adc.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <expected>
|
||||
|
||||
#include <units.hpp>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
class adc {
|
||||
public:
|
||||
enum class error {
|
||||
timeout
|
||||
};
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual std::expected<units::voltage, adc::error> get_reading() = 0;
|
||||
};
|
||||
};
|
||||
22
Chapter12/cpp_hal/hal/adc/inc/adc_stm32.hpp
Normal file
22
Chapter12/cpp_hal/hal/adc/inc/adc_stm32.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <adc.hpp>
|
||||
#include <units.hpp>
|
||||
|
||||
#include <stm32f0xx_hal.h>
|
||||
#include <stm32f072xb.h>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
|
||||
class adc_stm32 : public adc{
|
||||
public:
|
||||
adc_stm32(units::voltage ref_voltage) : ref_voltage_(ref_voltage) {}
|
||||
|
||||
void init() override;
|
||||
std::expected<units::voltage, adc::error> get_reading() override;
|
||||
private:
|
||||
ADC_HandleTypeDef adc_handle_;
|
||||
units::voltage ref_voltage_;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user