Convert illegal constexpr to static const pointers

We cannot get a constexpr definition of the register addresses, and any
reinterpret cast is currently illegal for a constexpr in c++17.

Change the SPI0, TIFR and TIMSK to volatile const pointers instead.

SPI0 has volatile members instead of marking the entire struct as
volatile, which is probably not a good idea as it technically drops the
volatile from the original pointer.
pull/192/head
Yuri D'Elia 2022-06-17 13:19:59 +02:00 committed by DRracer
parent d34b79b087
commit 4794cfea40
3 changed files with 9 additions and 6 deletions

View File

@ -3,7 +3,10 @@
#include <inttypes.h>
#include "gpio.h"
#define SPI0 ((hal::spi::SPI_TypeDef *)&SPCR)
#ifdef __AVR__
#define SPI0 ((hal::spi::SPI_TypeDef *const) & SPCR)
#endif
namespace hal {
/// SPI interface
@ -30,9 +33,9 @@ void Init(SPI_TypeDef *const hspi, SPI_InitTypeDef *const conf);
uint8_t TxRx(SPI_TypeDef *hspi, uint8_t val);
#ifdef __AVR__
constexpr SPI_TypeDef *TmcSpiBus = SPI0;
static SPI_TypeDef *const TmcSpiBus = SPI0;
#else
constexpr SPI_TypeDef *TmcSpiBus = nullptr;
static SPI_TypeDef *const TmcSpiBus = nullptr;
#endif
}

View File

@ -20,8 +20,8 @@ struct Tim8bit_TypeDef {
volatile uint8_t OCRxB;
};
constexpr volatile uint8_t *TIFR = &TIFR0;
constexpr volatile uint8_t *TIMSK = &TIMSK0;
static volatile uint8_t *const TIFR = &TIFR0;
static volatile uint8_t *const TIMSK = &TIMSK0;
struct Tim8bit_CTC_config {
uint8_t cs : 3; ///clock source as per datasheet. It is not consistent between timer types

View File

@ -18,7 +18,7 @@ enum MotorMode : uint8_t {
};
struct MotorParams {
const hal::spi::SPI_TypeDef *spi;
const hal::spi::SPI_TypeDef *const spi;
uint8_t idx; ///< SHR16 index
bool dirOn; ///< forward direction
gpio::GPIO_pin csPin; ///< CS pin