PinMap with namespace and constexpr

This commit is contained in:
hubmartin 2021-08-03 20:32:23 +02:00
parent 28abeae21b
commit b7aa04e1f5
13 changed files with 96 additions and 87 deletions

View file

@ -12,12 +12,12 @@ Battery::Battery() {
}
void Battery::Init() {
nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
}
void Battery::Update() {
isCharging = !nrf_gpio_pin_read(chargingPin);
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
if (isReading) {
return;

View file

@ -73,8 +73,6 @@ namespace Pinetime {
static constexpr uint8_t percentRemainingSamples = 5;
CircBuffer<percentRemainingSamples> percentRemainingBuffer {};
static constexpr uint32_t chargingPin = PINMAP_CHARGING_PIN;
static constexpr uint32_t powerPresentPin = 19;
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
uint16_t voltage = 0;
int percentRemaining = -1;

View file

@ -1,13 +1,13 @@
#include "BrightnessController.h"
#include <hal/nrf_gpio.h>
#include "displayapp/screens/Symbols.h"
#include "drivers/PinMap.h"
using namespace Pinetime::Controllers;
void BrightnessController::Init() {
nrf_gpio_cfg_output(pinLcdBacklight1);
nrf_gpio_cfg_output(pinLcdBacklight2);
nrf_gpio_cfg_output(pinLcdBacklight3);
nrf_gpio_cfg_output(PinMap::LcdBacklight1);
nrf_gpio_cfg_output(PinMap::LcdBacklight2);
nrf_gpio_cfg_output(PinMap::LcdBacklight3);
Set(level);
}
@ -16,24 +16,24 @@ void BrightnessController::Set(BrightnessController::Levels level) {
switch (level) {
default:
case Levels::High:
nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_clear(pinLcdBacklight2);
nrf_gpio_pin_clear(pinLcdBacklight3);
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
nrf_gpio_pin_clear(PinMap::LcdBacklight2);
nrf_gpio_pin_clear(PinMap::LcdBacklight3);
break;
case Levels::Medium:
nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_clear(pinLcdBacklight2);
nrf_gpio_pin_set(pinLcdBacklight3);
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
nrf_gpio_pin_clear(PinMap::LcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklight3);
break;
case Levels::Low:
nrf_gpio_pin_clear(pinLcdBacklight1);
nrf_gpio_pin_set(pinLcdBacklight2);
nrf_gpio_pin_set(pinLcdBacklight3);
nrf_gpio_pin_clear(PinMap::LcdBacklight1);
nrf_gpio_pin_set(PinMap::LcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklight3);
break;
case Levels::Off:
nrf_gpio_pin_set(pinLcdBacklight1);
nrf_gpio_pin_set(pinLcdBacklight2);
nrf_gpio_pin_set(pinLcdBacklight3);
nrf_gpio_pin_set(PinMap::LcdBacklight1);
nrf_gpio_pin_set(PinMap::LcdBacklight2);
nrf_gpio_pin_set(PinMap::LcdBacklight3);
break;
}
}

View file

@ -22,9 +22,6 @@ namespace Pinetime {
const char* ToString();
private:
static constexpr uint8_t pinLcdBacklight1 = 14;
static constexpr uint8_t pinLcdBacklight2 = 22;
static constexpr uint8_t pinLcdBacklight3 = 23;
Levels level = Levels::High;
Levels backupLevel = Levels::High;
};

View file

@ -2,6 +2,7 @@
#include <hal/nrf_gpio.h>
#include "systemtask/SystemTask.h"
#include "app_timer.h"
#include "drivers/PinMap.h"
APP_TIMER_DEF(vibTimer);
@ -11,8 +12,8 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
}
void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
nrf_gpio_cfg_output(PinMap::Motor);
nrf_gpio_pin_set(PinMap::Motor);
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
}
@ -21,11 +22,11 @@ void MotorController::SetDuration(uint8_t motorDuration) {
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
return;
nrf_gpio_pin_clear(pinMotor);
nrf_gpio_pin_clear(PinMap::Motor);
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
}
void MotorController::vibrate(void* p_context) {
nrf_gpio_pin_set(pinMotor);
nrf_gpio_pin_set(PinMap::Motor);
}

View file

@ -6,7 +6,6 @@
namespace Pinetime {
namespace Controllers {
static constexpr uint8_t pinMotor = 16;
class MotorController {
public:

View file

@ -3,6 +3,7 @@
#include <legacy/nrf_drv_gpiote.h>
#include <nrfx_log.h>
#include <task.h>
#include "drivers/PinMap.h"
using namespace Pinetime::Drivers;
@ -18,12 +19,12 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste
}
void Cst816S::Init() {
nrf_gpio_cfg_output(pinReset);
nrf_gpio_pin_set(pinReset);
nrf_gpio_cfg_output(PinMap::Cst816sReset);
nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
nrf_gpio_pin_clear(pinReset);
nrf_gpio_pin_clear(PinMap::Cst816sReset);
vTaskDelay(5);
nrf_gpio_pin_set(pinReset);
nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
// Wake the touchpanel up
@ -78,9 +79,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
}
void Cst816S::Sleep() {
nrf_gpio_pin_clear(pinReset);
nrf_gpio_pin_clear(PinMap::Cst816sReset);
vTaskDelay(5);
nrf_gpio_pin_set(pinReset);
nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
static constexpr uint8_t sleepValue = 0x03;
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);

View file

@ -1,7 +1,6 @@
#pragma once
#include "TwiMaster.h"
#include <drivers/PinMap.h>
namespace Pinetime {
namespace Drivers {
@ -40,8 +39,6 @@ namespace Pinetime {
void Wakeup();
private:
static constexpr uint8_t pinIrq = 28;
static constexpr uint8_t pinReset = PINMAP_CST816S_RESET_PIN;
static constexpr uint8_t lastTouchId = 0x0f;
static constexpr uint8_t touchPointNumIndex = 2;
static constexpr uint8_t touchMiscIndex = 8;

View file

@ -1,5 +1,42 @@
#pragma once
namespace Pinetime {
namespace PinMap {
#define WATCH_P8
#ifdef WATCH_P8
static constexpr uint8_t Charging = 19;
static constexpr uint8_t Cst816sReset = 13;
static constexpr uint8_t Button = 17;
#else
static constexpr uint8_t Charging = 12;
static constexpr uint8_t Cst816sReset = 10;
static constexpr uint8_t Button = 13;
#endif
static constexpr uint8_t Cst816sIrq = 28;
static constexpr uint8_t PowerPresent = 19;
static constexpr uint8_t Motor = 16;
static constexpr uint8_t LcdBacklight1 = 14;
static constexpr uint8_t LcdBacklight2 = 22;
static constexpr uint8_t LcdBacklight3 = 23;
static constexpr uint8_t SpiSck = 2;
static constexpr uint8_t SpiMosi = 3;
static constexpr uint8_t SpiMiso = 4;
static constexpr uint8_t SpiFlashCsn = 5;
static constexpr uint8_t SpiLcdCsn = 25;
static constexpr uint8_t LcdDataCommand = 18;
static constexpr uint8_t TwiScl = 7;
static constexpr uint8_t TwiSda = 6;
}
}
#ifdef WATCH_P8
// BatteryController.h

View file

@ -42,6 +42,7 @@
#include "drivers/St7789.h"
#include "drivers/TwiMaster.h"
#include "drivers/Cst816s.h"
#include "drivers/PinMap.h"
#include "systemtask/SystemTask.h"
#if NRF_LOG_ENABLED
@ -52,14 +53,6 @@ Pinetime::Logging::NrfLogger logger;
Pinetime::Logging::DummyLogger logger;
#endif
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiFlashCsn = 5;
static constexpr uint8_t pinLcdCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t pinTwiScl = 7;
static constexpr uint8_t pinTwiSda = 6;
static constexpr uint8_t touchPanelTwiAddress = 0x15;
static constexpr uint8_t motionSensorTwiAddress = 0x18;
static constexpr uint8_t heartRateSensorTwiAddress = 0x44;
@ -68,14 +61,14 @@ Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
Pinetime::Drivers::SpiMaster::Modes::Mode3,
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
pinSpiSck,
pinSpiMosi,
pinSpiMiso}};
Pinetime::PinMap::SpiSck,
Pinetime::PinMap::SpiMosi,
Pinetime::PinMap::SpiMiso}};
Pinetime::Drivers::Spi lcdSpi {spi, pinLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, pinLcdDataCommand};
Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Drivers::Spi flashSpi {spi, pinSpiFlashCsn};
Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn};
Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
// The TWI device should work @ up to 400Khz but there is a HW bug which prevent it from
@ -83,7 +76,7 @@ Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
// at ~390Khz with correct timings.
static constexpr uint32_t MaxTwiFrequencyWithoutHardwareBug {0x06200000};
Pinetime::Drivers::TwiMaster twiMaster {Pinetime::Drivers::TwiMaster::Modules::TWIM1,
Pinetime::Drivers::TwiMaster::Parameters {MaxTwiFrequencyWithoutHardwareBug, pinTwiSda, pinTwiScl}};
Pinetime::Drivers::TwiMaster::Parameters {MaxTwiFrequencyWithoutHardwareBug, Pinetime::PinMap::TwiSda, Pinetime::PinMap::TwiScl}};
Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
#ifdef PINETIME_IS_RECOVERY
static constexpr bool isFactory = true;
@ -106,8 +99,6 @@ Pinetime::Controllers::Battery batteryController;
Pinetime::Controllers::Ble bleController;
void ble_manager_set_ble_connection_callback(void (*connection)());
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
static constexpr uint8_t pinTouchIrq = 28;
static constexpr uint8_t pinPowerPresentIrq = 19;
Pinetime::Controllers::HeartRateController heartRateController;
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController);
@ -161,14 +152,14 @@ Pinetime::System::SystemTask systemTask(spi,
fs);
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) {
if (pin == Pinetime::PinMap::Cst816sIrq) {
systemTask.OnTouchEvent();
return;
}
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (pin == pinPowerPresentIrq and action == NRF_GPIOTE_POLARITY_TOGGLE) {
if (pin == Pinetime::PinMap::PowerPresent and action == NRF_GPIOTE_POLARITY_TOGGLE) {
xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return;

View file

@ -15,6 +15,7 @@
#include <components/brightness/BrightnessController.h>
#include <algorithm>
#include "recoveryImage.h"
#include "drivers/PinMap.h"
#include "displayapp/icons/infinitime/infinitime-nb.c"
#include "components/rle/RleDecoder.h"
@ -27,12 +28,6 @@ Pinetime::Logging::NrfLogger logger;
Pinetime::Logging::DummyLogger logger;
#endif
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiFlashCsn = 5;
static constexpr uint8_t pinLcdCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t displayWidth = 240;
static constexpr uint8_t displayHeight = 240;
@ -45,14 +40,14 @@ Pinetime::Drivers::SpiMaster spi {Pinetime::Drivers::SpiMaster::SpiModule::SPI0,
{Pinetime::Drivers::SpiMaster::BitOrder::Msb_Lsb,
Pinetime::Drivers::SpiMaster::Modes::Mode3,
Pinetime::Drivers::SpiMaster::Frequencies::Freq8Mhz,
pinSpiSck,
pinSpiMosi,
pinSpiMiso}};
Pinetime::Drivers::Spi flashSpi {spi, pinSpiFlashCsn};
Pinetime::PinMap::SpiSck,
Pinetime::PinMap::SpiMosi,
Pinetime::PinMap::SpiMiso}};
Pinetime::Drivers::Spi flashSpi {spi, Pinetime::PinMap::SpiFlashCsn};
Pinetime::Drivers::SpiNorFlash spiNorFlash {flashSpi};
Pinetime::Drivers::Spi lcdSpi {spi, pinLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, pinLcdDataCommand};
Pinetime::Drivers::Spi lcdSpi {spi, Pinetime::PinMap::SpiLcdCsn};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Components::Gfx gfx {lcd};
Pinetime::Controllers::BrightnessController brightnessController;

View file

@ -21,8 +21,10 @@
#include "drivers/SpiNorFlash.h"
#include "drivers/TwiMaster.h"
#include "drivers/Hrs3300.h"
#include "drivers/PinMap.h"
#include "main.h"
#include <memory>
using namespace Pinetime::System;
@ -149,7 +151,7 @@ void SystemTask::Work() {
heartRateSensor.Disable();
heartRateApp.Start();
nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
nrf_gpio_cfg_sense_input(PinMap::Button, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
@ -160,9 +162,9 @@ void SystemTask::Work() {
pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown;
nrfx_gpiote_in_init(pinButton, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler);
nrf_gpio_cfg_sense_input(pinTouchIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
pinConfig.skip_gpio_setup = true;
pinConfig.hi_accuracy = false;
@ -170,19 +172,19 @@ void SystemTask::Work() {
pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup;
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler);
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = NRF_GPIO_PIN_NOPULL;
pinConfig.is_watcher = false;
pinConfig.hi_accuracy = false;
pinConfig.skip_gpio_setup = true;
nrfx_gpiote_in_init(pinPowerPresentIrq, &pinConfig, nrfx_gpiote_evt_handler);
nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler);
if (nrf_gpio_pin_read(pinPowerPresentIrq)) {
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
if (nrf_gpio_pin_read(PinMap::PowerPresent)) {
nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
} else {
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
}
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
@ -354,7 +356,7 @@ void SystemTask::Work() {
monitor.Process();
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
dateTimeController.UpdateTime(systick_counter);
if (!nrf_gpio_pin_read(pinButton))
if (!nrf_gpio_pin_read(PinMap::Button))
watchdog.Kick();
}
// Clear diagnostic suppression

View file

@ -116,15 +116,6 @@ namespace Pinetime {
Pinetime::Controllers::FS& fs;
Pinetime::Controllers::NimbleController nimbleController;
static constexpr uint8_t pinSpiSck = 2;
static constexpr uint8_t pinSpiMosi = 3;
static constexpr uint8_t pinSpiMiso = 4;
static constexpr uint8_t pinSpiCsn = 25;
static constexpr uint8_t pinLcdDataCommand = 18;
static constexpr uint8_t pinButton = PINMAP_BUTTON_PIN;
static constexpr uint8_t pinTouchIrq = 28;
static constexpr uint8_t pinPowerPresentIrq = 19;
static void Process(void* instance);
void Work();
void ReloadIdleTimer();