diff --git a/firmware/emulation/hw_layer/poten.c b/firmware/emulation/hw_layer/poten.c index 38391bf772..f42367c384 100644 --- a/firmware/emulation/hw_layer/poten.c +++ b/firmware/emulation/hw_layer/poten.c @@ -44,13 +44,10 @@ static Logging logger; #if EFI_POTENTIOMETER || defined(__DOXYGEN__) Mcp42010Driver config[DIGIPOT_COUNT]; -void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, ioportid_t port, ioportmask_t pin) { - driver->spiConfig.end_cb = NULL; - driver->spiConfig.ssport = port; - driver->spiConfig.sspad = pin; +void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, brain_pin_e csPin) { driver->spiConfig.cr1 = SPI_POT_CONFIG; driver->spi = spi; - mySetPadMode("pot chip select", port, pin, PAL_STM32_MODE_OUTPUT); + initSpiCs(&driver->spiConfig, csPin); } static int getPotStep(int resistanceWA) { @@ -111,7 +108,7 @@ void initPotentiometers(board_configuration_s *boardConfiguration) { } initPotentiometer(&config[i], getSpiDevice(boardConfiguration->digitalPotentiometerSpiDevice), - getHwPort(csPin), getHwPin(csPin)); + csPin); } addConsoleActionII("pot", setPotResistanceCommand); diff --git a/firmware/emulation/hw_layer/poten.h b/firmware/emulation/hw_layer/poten.h index 39d0898a9e..5979cd4624 100644 --- a/firmware/emulation/hw_layer/poten.h +++ b/firmware/emulation/hw_layer/poten.h @@ -17,7 +17,7 @@ typedef struct { SPIConfig spiConfig; } Mcp42010Driver; -void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, ioportid_t port, ioportmask_t pin); +//void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, ioportid_t port, ioportmask_t pin); void initPotentiometers(board_configuration_s *boardConfiguration); void setPotResistance(Mcp42010Driver *driver, int channel, int resistance); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index b3f2b0b1df..a46b1e9812 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -289,3 +289,12 @@ SPIDriver * getSpiDevice(spi_device_e spiDevice) { return NULL; } +void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) { + spiConfig->end_cb = NULL; + ioportid_t port = getHwPort(csPin); + ioportmask_t pin = getHwPin(csPin); + spiConfig->ssport = port; + spiConfig->sspad = pin; + mySetPadMode("chip select", port, pin, PAL_STM32_MODE_OUTPUT); +} + diff --git a/firmware/hw_layer/hardware.h b/firmware/hw_layer/hardware.h index 8094d9d8f7..823f6e2919 100644 --- a/firmware/hw_layer/hardware.h +++ b/firmware/hw_layer/hardware.h @@ -10,12 +10,32 @@ #include "main.h" +// Peripherial Clock 42MHz SPI2 SPI3 +// Peripherial Clock 84MHz SPI1 SPI1 SPI2/3 +// 42 MHz 21 MHZ +#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) +// 21 MHz 10.5 MHz +#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) +// 10.5 MHz 5.25 MHz +#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) +// 5.25 MHz 2.626 MHz +#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) +// 2.626 MHz 1.3125 MHz +#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) +// 1.3125 MHz 656.25 KHz +#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) +// 656.25 KHz 328.125 KHz +#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) +// 328.125 KHz 164.06 KHz +#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ SPIDriver * getSpiDevice(spi_device_e spiDevice); +void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin); void turnOnSpi(spi_device_e device); void lockSpi(spi_device_e device); void unlockSpi(void); diff --git a/firmware/hw_layer/mcp3208.h b/firmware/hw_layer/mcp3208.h index f5bd6c7b70..ed0b68a0c9 100644 --- a/firmware/hw_layer/mcp3208.h +++ b/firmware/hw_layer/mcp3208.h @@ -37,16 +37,4 @@ void adc_in_out(McpAdcState *state); int getMcp3208adc(int channel); - -// Peripherial Clock 84MHz SPI1 SPI1 SPI2/3 -// Peripherial Clock 42MHz SPI2 SPI3 -#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) // 42 MHz 21 MHZ -#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) // 21 MHz 10.5 MHz -#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) // 10.5 MHz 5.25 MHz -#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) // 5.25 MHz 2.626 MHz -#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) // 2.626 MHz 1.3125 MHz -#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) // 1.3125 MHz 656.25 KHz -#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) // 656.25 KHz 328.125 KHz -#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) // 328.125 KHz 164.06 KHz - #endif /* MCP3208_H_ */ diff --git a/firmware/hw_layer/mmc_card.c b/firmware/hw_layer/mmc_card.c index d0e1960e9d..7e96dbb096 100644 --- a/firmware/hw_layer/mmc_card.c +++ b/firmware/hw_layer/mmc_card.c @@ -33,24 +33,6 @@ static THD_WORKING_AREA(tp_MMC_Monitor,UTILITY_THREAD_STACK_SIZE); // MMC monit */ MMCDriver MMCD1; -// Peripherial Clock 42MHz SPI2 SPI3 -// Peripherial Clock 84MHz SPI1 SPI1 SPI2/3 -// 42 MHz 21 MHZ -#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) -// 21 MHz 10.5 MHz -#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) -// 10.5 MHz 5.25 MHz -#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) -// 5.25 MHz 2.626 MHz -#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) -// 2.626 MHz 1.3125 MHz -#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) -// 1.3125 MHz 656.25 KHz -#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) -// 656.25 KHz 328.125 KHz -#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) -// 328.125 KHz 164.06 KHz -#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) static SPIConfig hs_spicfg = { NULL, SPI_SD_MODULE_PORT, SPI_SD_MODULE_PIN, SPI_BaudRatePrescaler_8 }; static SPIConfig ls_spicfg = { NULL, SPI_SD_MODULE_PORT, SPI_SD_MODULE_PIN,