improve macro readability

This commit is contained in:
Hierophect 2019-10-09 16:06:23 -04:00
parent 4ce7a4cfdb
commit 06b2fed518
3 changed files with 9 additions and 7 deletions

View file

@ -42,13 +42,13 @@
//DAC is shared between both channels. //DAC is shared between both channels.
//TODO: store as struct with channel info, automatically turn it off if unused //TODO: store as struct with channel info, automatically turn it off if unused
//on both channels for power save? //on both channels for power save?
#if defined(HAS_DAC) #if HAS_DAC
DAC_HandleTypeDef handle; DAC_HandleTypeDef handle;
#endif #endif
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self, void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
#if !defined(HAS_DAC) #if !(HAS_DAC)
mp_raise_ValueError(translate("No DAC on chip")); mp_raise_ValueError(translate("No DAC on chip"));
#else #else
if (pin == &pin_PA04) { if (pin == &pin_PA04) {
@ -93,7 +93,7 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
} }
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
#if defined(HAS_DAC) #if HAS_DAC
reset_pin_number(self->pin->port,self->pin->number); reset_pin_number(self->pin->port,self->pin->number);
self->pin = mp_const_none; self->pin = mp_const_none;
self->deinited = true; self->deinited = true;
@ -103,14 +103,14 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
uint16_t value) { uint16_t value) {
#if defined(HAS_DAC) #if HAS_DAC
HAL_DAC_SetValue(&handle, self->channel, DAC_ALIGN_12B_R, value >> 4); HAL_DAC_SetValue(&handle, self->channel, DAC_ALIGN_12B_R, value >> 4);
HAL_DAC_Start(&handle, self->channel); HAL_DAC_Start(&handle, self->channel);
#endif #endif
} }
void analogout_reset(void) { void analogout_reset(void) {
#if defined(HAS_DAC) #if HAS_DAC
__HAL_RCC_DAC_CLK_DISABLE(); __HAL_RCC_DAC_CLK_DISABLE();
HAL_DAC_DeInit(&handle); HAL_DAC_DeInit(&handle);
#endif #endif

View file

@ -36,7 +36,7 @@
typedef struct { typedef struct {
mp_obj_base_t base; mp_obj_base_t base;
#if defined(HAS_DAC) #if HAS_DAC
DAC_ChannelConfTypeDef ch_handle; DAC_ChannelConfTypeDef ch_handle;
#endif #endif
const mcu_pin_obj_t * pin; const mcu_pin_obj_t * pin;

View file

@ -102,17 +102,19 @@ typedef struct {
//Starter Lines //Starter Lines
#ifdef STM32F411xE #ifdef STM32F411xE
#define HAS_DAC 0
#include "stm32f411xe/periph.h" #include "stm32f411xe/periph.h"
#endif #endif
#ifdef STM32F412Zx #ifdef STM32F412Zx
#define HAS_DAC 0
#include "stm32f412zx/periph.h" #include "stm32f412zx/periph.h"
#endif #endif
//Foundation Lines //Foundation Lines
#ifdef STM32F405xx #ifdef STM32F405xx
#define HAS_DAC #define HAS_DAC 1
#include "stm32f405xx/periph.h" #include "stm32f405xx/periph.h"
#endif #endif