diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-06 18:27:54 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-06-06 23:09:58 (GMT) |
| commit | 7c45f185a32c7bcff47c8fda1acdec82d3213717 (patch) | |
| tree | 53b0419fe2a19e6ec5c89d0be0a11dcd8d4ceb00 /src/drivers | |
| parent | 94b1b330fc1f6e941a797fedabade4e790e28bc2 (diff) | |
| parent | 35dcf8c8607483c104711c9398d47d57147f4389 (diff) | |
Merge remote-tracking branch 'origin/develop' into analog24
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Bma421.cpp | 14 | ||||
| -rw-r--r-- | src/drivers/Bma421.h | 6 | ||||
| -rw-r--r-- | src/drivers/Bma421_C/bma4.c | 4 | ||||
| -rw-r--r-- | src/drivers/Bma421_C/bma4_defs.h | 2 | ||||
| -rw-r--r-- | src/drivers/Cst816s.cpp | 11 | ||||
| -rw-r--r-- | src/drivers/Cst816s.h | 11 | ||||
| -rw-r--r-- | src/drivers/DebugPins.cpp | 10 | ||||
| -rw-r--r-- | src/drivers/PinMap.h | 26 | ||||
| -rw-r--r-- | src/drivers/SpiMaster.cpp | 2 | ||||
| -rw-r--r-- | src/drivers/SpiNorFlash.cpp | 22 | ||||
| -rw-r--r-- | src/drivers/SpiNorFlash.h | 4 | ||||
| -rw-r--r-- | src/drivers/St7789.cpp | 8 | ||||
| -rw-r--r-- | src/drivers/St7789.h | 8 | ||||
| -rw-r--r-- | src/drivers/TwiMaster.cpp | 20 |
14 files changed, 80 insertions, 68 deletions
diff --git a/src/drivers/Bma421.cpp b/src/drivers/Bma421.cpp index 2f60f42..539cc8d 100644 --- a/src/drivers/Bma421.cpp +++ b/src/drivers/Bma421.cpp @@ -42,10 +42,16 @@ void Bma421::Init() { if (ret != BMA4_OK) return; - switch(bma.chip_id) { - case BMA423_CHIP_ID: deviceType = DeviceTypes::BMA421; break; - case BMA425_CHIP_ID: deviceType = DeviceTypes::BMA425; break; - default: deviceType = DeviceTypes::Unknown; break; + switch (bma.chip_id) { + case BMA423_CHIP_ID: + deviceType = DeviceTypes::BMA421; + break; + case BMA425_CHIP_ID: + deviceType = DeviceTypes::BMA425; + break; + default: + deviceType = DeviceTypes::Unknown; + break; } ret = bma423_write_config_file(&bma); diff --git a/src/drivers/Bma421.h b/src/drivers/Bma421.h index 2e40883..fef4dc0 100644 --- a/src/drivers/Bma421.h +++ b/src/drivers/Bma421.h @@ -10,11 +10,7 @@ namespace Pinetime { class TwiMaster; class Bma421 { public: - enum class DeviceTypes : uint8_t { - Unknown, - BMA421, - BMA425 - }; + enum class DeviceTypes : uint8_t { Unknown, BMA421, BMA425 }; struct Values { uint32_t steps; int16_t x; diff --git a/src/drivers/Bma421_C/bma4.c b/src/drivers/Bma421_C/bma4.c index 59e2a72..8472147 100644 --- a/src/drivers/Bma421_C/bma4.c +++ b/src/drivers/Bma421_C/bma4.c @@ -621,7 +621,7 @@ static int8_t get_average_of_sensor_data(uint8_t accel_en, * * @param[in] accel_en : Variable to store status of accel * @param[in] accel_g_axis : Accel axis to FOC - * @param[in] avg_foc_data : Average value of sensor sample datas + * @param[in] avg_foc_data : Average value of sensor sample data * @param[in] dev : Structure instance of bma4_dev. * * @return Result of API execution status @@ -637,7 +637,7 @@ static int8_t validate_foc_position(uint8_t accel_en, /*! * @brief This internal API validates accel FOC axis given as input * - * @param[in] avg_foc_data : Average value of sensor sample datas + * @param[in] avg_foc_data : Average value of sensor sample data * @param[in] dev : Structure instance of bma4_dev. * * @return Result of API execution status diff --git a/src/drivers/Bma421_C/bma4_defs.h b/src/drivers/Bma421_C/bma4_defs.h index 2db99c0..45e4920 100644 --- a/src/drivers/Bma421_C/bma4_defs.h +++ b/src/drivers/Bma421_C/bma4_defs.h @@ -259,7 +259,7 @@ #define BMA4_ACCEL_RANGE_8G UINT8_C(2) #define BMA4_ACCEL_RANGE_16G UINT8_C(3) -/**\name CONDITION CHECK FOR READING AND WRTING DATA*/ +/**\name CONDITION CHECK FOR READING AND WRITING DATA*/ #define BMA4_MAX_VALUE_FIFO_FILTER UINT8_C(1) #define BMA4_MAX_VALUE_SPI3 UINT8_C(1) #define BMA4_MAX_VALUE_SELFTEST_AMP UINT8_C(1) diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index e9573df..cf10c89 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -80,14 +80,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]); // Validity check - if(x >= maxX || y >= maxY || - (gesture != Gestures::None && - gesture != Gestures::SlideDown && - gesture != Gestures::SlideUp && - gesture != Gestures::SlideLeft && - gesture != Gestures::SlideRight && - gesture != Gestures::SingleTap && - gesture != Gestures::DoubleTap && + if (x >= maxX || y >= maxY || + (gesture != Gestures::None && gesture != Gestures::SlideDown && gesture != Gestures::SlideUp && gesture != Gestures::SlideLeft && + gesture != Gestures::SlideRight && gesture != Gestures::SingleTap && gesture != Gestures::DoubleTap && gesture != Gestures::LongPress)) { info.isValid = false; return info; diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 4a548d4..9d426c9 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -44,21 +44,22 @@ namespace Pinetime { uint8_t GetFwVersion() const { return fwVersion; } + private: bool CheckDeviceIds(); // Unused/Unavailable commented out static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t touchPointNumIndex = 2; - //static constexpr uint8_t touchEventIndex = 3; + // static constexpr uint8_t touchEventIndex = 3; static constexpr uint8_t touchXHighIndex = 3; static constexpr uint8_t touchXLowIndex = 4; - //static constexpr uint8_t touchIdIndex = 5; + // static constexpr uint8_t touchIdIndex = 5; static constexpr uint8_t touchYHighIndex = 5; static constexpr uint8_t touchYLowIndex = 6; - //static constexpr uint8_t touchStep = 6; - //static constexpr uint8_t touchXYIndex = 7; - //static constexpr uint8_t touchMiscIndex = 8; + // static constexpr uint8_t touchStep = 6; + // static constexpr uint8_t touchXYIndex = 7; + // static constexpr uint8_t touchMiscIndex = 8; static constexpr uint8_t maxX = 240; static constexpr uint8_t maxY = 240; diff --git a/src/drivers/DebugPins.cpp b/src/drivers/DebugPins.cpp index 9209128..4b2f0f1 100644 --- a/src/drivers/DebugPins.cpp +++ b/src/drivers/DebugPins.cpp @@ -19,16 +19,16 @@ void debugpins_init() { nrf_gpio_pin_clear(DebugPin4); } void debugpins_set(debugpins_pins pin) { - nrf_gpio_pin_set((uint32_t) (pin)); + nrf_gpio_pin_set(static_cast<uint32_t>(pin)); } void debugpins_clear(debugpins_pins pin) { - nrf_gpio_pin_clear((uint32_t) (pin)); + nrf_gpio_pin_clear(static_cast<uint32_t>(pin)); } void debugpins_pulse(debugpins_pins pin) { - nrf_gpio_pin_set((uint32_t) (pin)); - nrf_gpio_pin_clear((uint32_t) (pin)); + nrf_gpio_pin_set(static_cast<uint32_t>(pin)); + nrf_gpio_pin_clear(static_cast<uint32_t>(pin)); } #else void debugpins_init() { @@ -42,4 +42,4 @@ void debugpins_clear(debugpins_pins pin) { void debugpins_pulse(debugpins_pins pin) { } -#endif
\ No newline at end of file +#endif diff --git a/src/drivers/PinMap.h b/src/drivers/PinMap.h index 579bf38..833c647 100644 --- a/src/drivers/PinMap.h +++ b/src/drivers/PinMap.h @@ -3,21 +3,23 @@ namespace Pinetime { namespace PinMap { - - #ifdef WATCH_P8 - // COLMI P8 - static constexpr uint8_t Charging = 19; - static constexpr uint8_t Cst816sReset = 13; - static constexpr uint8_t Button = 17; - #else - // Pinetime - static constexpr uint8_t Charging = 12; - static constexpr uint8_t Cst816sReset = 10; - static constexpr uint8_t Button = 13; - #endif +#ifdef WATCH_P8 + // COLMI P8 + static constexpr uint8_t Charging = 19; + static constexpr uint8_t Cst816sReset = 13; + static constexpr uint8_t Button = 17; +#else + // Pinetime + static constexpr uint8_t Charging = 12; + static constexpr uint8_t Cst816sReset = 10; + static constexpr uint8_t Button = 13; +#endif + + static constexpr uint8_t ButtonEnable = 15; static constexpr uint8_t Cst816sIrq = 28; static constexpr uint8_t PowerPresent = 19; + static constexpr uint8_t Bma421Irq = 8; static constexpr uint8_t Motor = 16; diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 747dbc8..38f72fe 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -10,7 +10,7 @@ SpiMaster::SpiMaster(const SpiMaster::SpiModule spi, const SpiMaster::Parameters } bool SpiMaster::Init() { - if(mutex == nullptr) { + if (mutex == nullptr) { mutex = xSemaphoreCreateBinary(); ASSERT(mutex != nullptr); } diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp index ebe3174..28f82fe 100644 --- a/src/drivers/SpiNorFlash.cpp +++ b/src/drivers/SpiNorFlash.cpp @@ -11,8 +11,10 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} { void SpiNorFlash::Init() { device_id = ReadIdentificaion(); - NRF_LOG_INFO( - "[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density); + NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", + device_id.manufacturer, + device_id.type, + device_id.density); } void SpiNorFlash::Uninit() { @@ -70,7 +72,10 @@ uint8_t SpiNorFlash::ReadConfigurationRegister() { void SpiNorFlash::Read(uint32_t address, uint8_t* buffer, size_t size) { static constexpr uint8_t cmdSize = 4; - uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::Read), (uint8_t) (address >> 16U), (uint8_t) (address >> 8U), (uint8_t) address}; + uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::Read), + static_cast<uint8_t>(address >> 16U), + static_cast<uint8_t>(address >> 8U), + static_cast<uint8_t>(address)}; spi.Read(reinterpret_cast<uint8_t*>(&cmd), cmdSize, buffer, size); } @@ -82,9 +87,9 @@ void SpiNorFlash::WriteEnable() { void SpiNorFlash::SectorErase(uint32_t sectorAddress) { static constexpr uint8_t cmdSize = 4; uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::SectorErase), - (uint8_t) (sectorAddress >> 16U), - (uint8_t) (sectorAddress >> 8U), - (uint8_t) sectorAddress}; + static_cast<uint8_t>(sectorAddress >> 16U), + static_cast<uint8_t>(sectorAddress >> 8U), + static_cast<uint8_t>(sectorAddress)}; WriteEnable(); while (!WriteEnabled()) @@ -121,7 +126,10 @@ void SpiNorFlash::Write(uint32_t address, const uint8_t* buffer, size_t size) { uint32_t pageLimit = (addr & ~(pageSize - 1u)) + pageSize; uint32_t toWrite = pageLimit - addr > len ? len : pageLimit - addr; - uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::PageProgram), (uint8_t) (addr >> 16U), (uint8_t) (addr >> 8U), (uint8_t) addr}; + uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::PageProgram), + static_cast<uint8_t>(addr >> 16U), + static_cast<uint8_t>(addr >> 8U), + static_cast<uint8_t>(addr)}; WriteEnable(); while (!WriteEnabled()) diff --git a/src/drivers/SpiNorFlash.h b/src/drivers/SpiNorFlash.h index ed6ab31..ad4d090 100644 --- a/src/drivers/SpiNorFlash.h +++ b/src/drivers/SpiNorFlash.h @@ -13,11 +13,11 @@ namespace Pinetime { SpiNorFlash(SpiNorFlash&&) = delete; SpiNorFlash& operator=(SpiNorFlash&&) = delete; - typedef struct __attribute__((packed)) { + struct __attribute__((packed)) Identification { uint8_t manufacturer = 0; uint8_t type = 0; uint8_t density = 0; - } Identification; + }; Identification ReadIdentificaion(); uint8_t ReadStatusRegister(); diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index fd1366f..3ed1beb 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -23,6 +23,7 @@ void St7789::Init() { RowAddressSet(); DisplayInversionOn(); NormalModeOn(); + SetVdv(); DisplayOn(); } @@ -114,6 +115,13 @@ void St7789::WriteToRam() { WriteCommand(static_cast<uint8_t>(Commands::WriteToRam)); } +void St7789::SetVdv() { + // By default there is a large step from pixel brightness zero to one. + // After experimenting with VCOMS, VRH and VDV, this was found to produce good results. + WriteCommand(static_cast<uint8_t>(Commands::VdvSet)); + WriteData(0x10); +} + void St7789::DisplayOff() { WriteCommand(static_cast<uint8_t>(Commands::DisplayOff)); nrf_delay_ms(500); diff --git a/src/drivers/St7789.h b/src/drivers/St7789.h index 4fbccbe..8c2ac09 100644 --- a/src/drivers/St7789.h +++ b/src/drivers/St7789.h @@ -22,9 +22,6 @@ namespace Pinetime { void DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* data, size_t size); - void DisplayOn(); - void DisplayOff(); - void Sleep(); void Wakeup(); @@ -42,7 +39,11 @@ namespace Pinetime { void DisplayInversionOn(); void NormalModeOn(); void WriteToRam(); + void DisplayOn(); + void DisplayOff(); + void SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); + void SetVdv(); void WriteCommand(uint8_t cmd); void WriteSpi(const uint8_t* data, size_t size); @@ -61,6 +62,7 @@ namespace Pinetime { VerticalScrollDefinition = 0x33, VerticalScrollStartAddress = 0x37, ColMod = 0x3a, + VdvSet = 0xc4, }; void WriteData(uint8_t data); void ColumnAddressSet(); diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp index 9b456d5..25d23c2 100644 --- a/src/drivers/TwiMaster.cpp +++ b/src/drivers/TwiMaster.cpp @@ -13,19 +13,13 @@ TwiMaster::TwiMaster(NRF_TWIM_Type* module, uint32_t frequency, uint8_t pinSda, } void TwiMaster::ConfigurePins() const { - NRF_GPIO->PIN_CNF[pinScl] = - (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | - (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | - (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | - (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); - - NRF_GPIO->PIN_CNF[pinSda] = - (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | - (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | - (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | - (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | - (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); + NRF_GPIO->PIN_CNF[pinScl] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); + + NRF_GPIO->PIN_CNF[pinSda] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos); } void TwiMaster::Init() { |
