Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev nRF51822
Diff: main.cpp
- Revision:
- 48:d6938de02f62
- Parent:
- 47:5bf2ae8cc710
- Child:
- 49:09ae6fb04a32
--- a/main.cpp Mon Aug 29 12:38:32 2016 +0000
+++ b/main.cpp Mon Aug 29 14:09:09 2016 +0000
@@ -26,19 +26,20 @@
#include "config.h"
RawSerial serial(USBTX, USBRX);
-I2C i2c(I2C_SDA0, I2C_SCL0);
-KeyboardMatrixController keyboardMatrixController(i2c);
-Keymap keymap;
+
+static I2C i2c(I2C_SDA0, I2C_SCL0);
+static KeyboardMatrixController keyboardMatrixController(i2c);
+static Keymap keymap;
// Interrupt from MCP23017
// (pulled-up and two MCP23017 is configured with open drain INT)
-InterruptIn keyboardInterruptIn(P0_5);
+static InterruptIn keyboardInterruptIn(P0_5);
#define PIN_STATUS_LED P0_4
-DigitalOut statusLed(PIN_STATUS_LED, 0);
+static DigitalOut statusLed(PIN_STATUS_LED, 0);
// timeout for status led and wakeup from sleep
-Timeout timeout;
+static Timeout timeout;
// ROWS=8
// COLS=16
@@ -51,22 +52,22 @@
// delay for interrupt
static volatile int8_t pollCount = 50;
-void keyboardInterrupt() {
+static void keyboardInterrupt() {
// just for wakeup
pollCount = 25;
}
-void powerOff() {
+static void powerOff() {
DEBUG_PRINTF("power off\r\n");
NRF_POWER->SYSTEMOFF = 1;
}
-void tickerStatus() {
+static void tickerStatus() {
statusLed = !statusLed;
}
static bool updateStatudLedEnabled = false;
-void updateStatusLed() {
+static void updateStatusLed() {
switch (HIDController::status()) {
case TIMEOUT:
case DISCONNECTED:
@@ -84,7 +85,7 @@
}
static volatile bool keyIntervalInterrupt = false;
-void wakeupKeyIntervalSleep() {
+static void wakeupKeyIntervalSleep() {
keyIntervalInterrupt = true;
}
@@ -92,13 +93,13 @@
int main(void) {
{
- uint32_t reason = NRF_POWER->RESETREAS;
+ const uint32_t reason = NRF_POWER->RESETREAS;
NRF_POWER->RESETREAS = 0xffffffff; // clear reason
// reset cause should be shown everytime
serial.printf("init [%x]\r\n", reason);
}
- float battery = BatteryLevel::readBatteryVoltage();
+ const float battery = BatteryLevel::readBatteryVoltage();
if (battery < BatteryLevel::BATTERY_LOW) {
powerOff();
}
@@ -219,7 +220,7 @@
bool queue = false;
for (int col = 0; col < COLS; col++) {
- uint8_t changed = keysPrev[col] ^ keysCurr[col];
+ const uint8_t changed = keysPrev[col] ^ keysCurr[col];
if (changed) queue = true;
for (int row = 0; row < ROWS; row++) {
if (changed & (1<<row)) {
@@ -259,9 +260,9 @@
} else {
if (!updateStatudLedEnabled) updateStatusLed();
- float batteryVoltage = BatteryLevel::readBatteryVoltage();
- uint8_t batteryPercentage = BatteryLevel::readBatteryPercentage(batteryVoltage);
- bool isLowBattery = batteryVoltage < BatteryLevel::BATTERY_LOW;
+ const float batteryVoltage = BatteryLevel::readBatteryVoltage();
+ const uint8_t batteryPercentage = BatteryLevel::readBatteryPercentage(batteryVoltage);
+ const bool isLowBattery = batteryVoltage < BatteryLevel::BATTERY_LOW;
DEBUG_PRINTF("%d%% [%d:%s] %s\r\n",
batteryPercentage,
@@ -287,7 +288,7 @@
// TWI / SPI / UART must be disabled and boot without debug mode
while (NRF_UART0->EVENTS_TXDRDY != 1);
- uint32_t tx = NRF_UART0->PSELTXD;
+ const uint32_t tx = NRF_UART0->PSELTXD;
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);