Merge branch 'master' into fix_missing_defines

pull/162/head
SQFMI 2022-05-06 23:54:27 -04:00 committed by GitHub
commit 4b739afbd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 7702 additions and 6425 deletions

View File

@ -15,8 +15,9 @@ Visit [**https://watchy.sqfmi.com**](https://watchy.sqfmi.com) for documentation
2. Install this library (search for **Watchy** in the library manager), and any other dependencies when prompted 2. Install this library (search for **Watchy** in the library manager), and any other dependencies when prompted
3. Check out the examples under ```Examples``` -> ```Watchy``` 3. Check out the examples under ```Examples``` -> ```Watchy```
4. Compile & Upload with these board settings: 4. Compile & Upload with these board settings:
* Board: "ESP32 Dev Module" * Board: "Watchy"
* Partition Scheme: "Minimal SPIFFS" * Partition Scheme: "Huge App"
* Board Revision: "Watchy v2.0" (if purchased in 2022)
* All Other Settings: leave to default * All Other Settings: leave to default
You may also have to install the [CP2104 USB to Serial drivers](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) if the port is not automatically detected. You may also have to install the [CP2104 USB to Serial drivers](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) if the port is not automatically detected.

View File

@ -6,7 +6,8 @@
#define SERVICE_UUID_OTA "86b12865-4b70-4893-8ce6-9864fc00374d" #define SERVICE_UUID_OTA "86b12865-4b70-4893-8ce6-9864fc00374d"
#define CHARACTERISTIC_UUID_FW "86b12866-4b70-4893-8ce6-9864fc00374d" #define CHARACTERISTIC_UUID_FW "86b12866-4b70-4893-8ce6-9864fc00374d"
#define CHARACTERISTIC_UUID_HW_VERSION "86b12867-4b70-4893-8ce6-9864fc00374d" #define CHARACTERISTIC_UUID_HW_VERSION "86b12867-4b70-4893-8ce6-9864fc00374d"
#define CHARACTERISTIC_UUID_WATCHFACE_NAME "86b12868-4b70-4893-8ce6-9864fc00374d" #define CHARACTERISTIC_UUID_WATCHFACE_NAME \
"86b12868-4b70-4893-8ce6-9864fc00374d"
#define FULL_PACKET 512 #define FULL_PACKET 512
#define CHARPOS_UPDATE_FLAG 5 #define CHARPOS_UPDATE_FLAG 5
@ -22,78 +23,63 @@ int status = -1;
int bytesReceived = 0; int bytesReceived = 0;
bool updateFlag = false; bool updateFlag = false;
class BLECustomServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer *pServer) { status = STATUS_CONNECTED; };
class BLECustomServerCallbacks: public BLEServerCallbacks { void onDisconnect(BLEServer *pServer) { status = STATUS_DISCONNECTED; }
void onConnect(BLEServer* pServer) {
status = STATUS_CONNECTED;
};
void onDisconnect(BLEServer* pServer) {
status = STATUS_DISCONNECTED;
}
}; };
class otaCallback: public BLECharacteristicCallbacks { class otaCallback : public BLECharacteristicCallbacks {
public: public:
otaCallback(BLE* ble) { otaCallback(BLE *ble) { _p_ble = ble; }
_p_ble = ble; BLE *_p_ble;
}
BLE* _p_ble;
void onWrite(BLECharacteristic *pCharacteristic); void onWrite(BLECharacteristic *pCharacteristic);
}; };
void otaCallback::onWrite(BLECharacteristic *pCharacteristic) void otaCallback::onWrite(BLECharacteristic *pCharacteristic) {
{
std::string rxData = pCharacteristic->getValue(); std::string rxData = pCharacteristic->getValue();
if (!updateFlag) { //If it's the first packet of OTA since bootup, begin OTA if (!updateFlag) { // If it's the first packet of OTA since bootup, begin OTA
//Serial.println("Begin FW Update"); // Serial.println("Begin FW Update");
esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN, &otaHandler); esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN,
&otaHandler);
updateFlag = true; updateFlag = true;
status = STATUS_UPDATING; status = STATUS_UPDATING;
} }
if (_p_ble != NULL) if (_p_ble != NULL) {
{ if (rxData.length() > 0) {
if (rxData.length() > 0)
{
esp_ota_write(otaHandler, rxData.c_str(), rxData.length()); esp_ota_write(otaHandler, rxData.c_str(), rxData.length());
bytesReceived = bytesReceived + rxData.length(); bytesReceived = bytesReceived + rxData.length();
if (rxData.length() != FULL_PACKET) if (rxData.length() != FULL_PACKET) {
{
esp_ota_end(otaHandler); esp_ota_end(otaHandler);
//Serial.println("End FW Update"); // Serial.println("End FW Update");
if (ESP_OK == esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL))) { if (ESP_OK == esp_ota_set_boot_partition(
esp_ota_get_next_update_partition(NULL))) {
status = STATUS_READY; status = STATUS_READY;
} } else {
else { // Serial.println("Upload Error");
//Serial.println("Upload Error");
} }
} }
} }
} }
uint8_t txData[5] = {1, 2, 3, 4, 5}; uint8_t txData[5] = {1, 2, 3, 4, 5};
//delay(1000); // delay(1000);
pCharacteristic->setValue((uint8_t*)txData, 5); pCharacteristic->setValue((uint8_t *)txData, 5);
pCharacteristic->notify(); pCharacteristic->notify();
} }
// //
// Constructor // Constructor
BLE::BLE(void) { BLE::BLE(void) {}
}
// //
// Destructor // Destructor
BLE::~BLE(void) BLE::~BLE(void) {}
{
}
// //
// begin // begin
bool BLE::begin(const char* localName = "Watchy BLE OTA") { bool BLE::begin(const char *localName = "Watchy BLE OTA") {
// Create the BLE Device // Create the BLE Device
BLEDevice::init(localName); BLEDevice::init(localName);
@ -107,24 +93,17 @@ bool BLE::begin(const char* localName = "Watchy BLE OTA") {
// Create a BLE Characteristic // Create a BLE Characteristic
pESPOTAIdCharacteristic = pESPOTAService->createCharacteristic( pESPOTAIdCharacteristic = pESPOTAService->createCharacteristic(
CHARACTERISTIC_UUID_ID, CHARACTERISTIC_UUID_ID, BLECharacteristic::PROPERTY_READ);
BLECharacteristic::PROPERTY_READ
);
pVersionCharacteristic = pService->createCharacteristic( pVersionCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_HW_VERSION, CHARACTERISTIC_UUID_HW_VERSION, BLECharacteristic::PROPERTY_READ);
BLECharacteristic::PROPERTY_READ
);
pWatchFaceNameCharacteristic = pService->createCharacteristic( pWatchFaceNameCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_WATCHFACE_NAME, CHARACTERISTIC_UUID_WATCHFACE_NAME, BLECharacteristic::PROPERTY_READ);
BLECharacteristic::PROPERTY_READ
);
pOtaCharacteristic = pService->createCharacteristic( pOtaCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_FW, CHARACTERISTIC_UUID_FW,
BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_WRITE BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_WRITE);
);
pOtaCharacteristic->addDescriptor(new BLE2902()); pOtaCharacteristic->addDescriptor(new BLE2902());
pOtaCharacteristic->setCallbacks(new otaCallback(this)); pOtaCharacteristic->setCallbacks(new otaCallback(this));
@ -137,17 +116,15 @@ bool BLE::begin(const char* localName = "Watchy BLE OTA") {
pServer->getAdvertising()->addServiceUUID(SERVICE_UUID_ESPOTA); pServer->getAdvertising()->addServiceUUID(SERVICE_UUID_ESPOTA);
pServer->getAdvertising()->start(); pServer->getAdvertising()->start();
uint8_t hardwareVersion[5] = {HARDWARE_VERSION_MAJOR, HARDWARE_VERSION_MINOR, SOFTWARE_VERSION_MAJOR, SOFTWARE_VERSION_MINOR, SOFTWARE_VERSION_PATCH}; uint8_t hardwareVersion[5] = {HARDWARE_VERSION_MAJOR, HARDWARE_VERSION_MINOR,
pVersionCharacteristic->setValue((uint8_t*)hardwareVersion, 5); SOFTWARE_VERSION_MAJOR, SOFTWARE_VERSION_MINOR,
SOFTWARE_VERSION_PATCH};
pVersionCharacteristic->setValue((uint8_t *)hardwareVersion, 5);
pWatchFaceNameCharacteristic->setValue("Watchy 7 Segment"); pWatchFaceNameCharacteristic->setValue("Watchy 7 Segment");
return true; return true;
} }
int BLE::updateStatus(){ int BLE::updateStatus() { return status; }
return status;
}
int BLE::howManyBytes(){ int BLE::howManyBytes() { return bytesReceived; }
return bytesReceived;
}

View File

@ -3,10 +3,10 @@
#include "Arduino.h" #include "Arduino.h"
#include <BLE2902.h>
#include <BLEDevice.h> #include <BLEDevice.h>
#include <BLEServer.h> #include <BLEServer.h>
#include <BLEUtils.h> #include <BLEUtils.h>
#include <BLE2902.h>
#include "esp_ota_ops.h" #include "esp_ota_ops.h"
@ -14,29 +14,27 @@
class BLE; class BLE;
class BLE class BLE {
{ public:
public:
BLE(void); BLE(void);
~BLE(void); ~BLE(void);
bool begin(const char* localName); bool begin(const char *localName);
int updateStatus(); int updateStatus();
int howManyBytes(); int howManyBytes();
private: private:
String local_name; String local_name;
BLEServer *pServer = NULL; BLEServer *pServer = NULL;
BLEService *pESPOTAService = NULL; BLEService *pESPOTAService = NULL;
BLECharacteristic * pESPOTAIdCharacteristic = NULL; BLECharacteristic *pESPOTAIdCharacteristic = NULL;
BLEService *pService = NULL; BLEService *pService = NULL;
BLECharacteristic * pVersionCharacteristic = NULL; BLECharacteristic *pVersionCharacteristic = NULL;
BLECharacteristic * pOtaCharacteristic = NULL; BLECharacteristic *pOtaCharacteristic = NULL;
BLECharacteristic * pWatchFaceNameCharacteristic = NULL; BLECharacteristic *pWatchFaceNameCharacteristic = NULL;
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
#include "Watchy.h" #include "Watchy.h"
WatchyRTC Watchy::RTC; WatchyRTC Watchy::RTC;
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> Watchy::display(GxEPD2_154_D67(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY)); GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> Watchy::display(
GxEPD2_154_D67(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY));
RTC_DATA_ATTR int guiState; RTC_DATA_ATTR int guiState;
RTC_DATA_ATTR int menuIndex; RTC_DATA_ATTR int menuIndex;
@ -12,65 +13,69 @@ RTC_DATA_ATTR weatherData currentWeather;
RTC_DATA_ATTR int weatherIntervalCounter = -1; RTC_DATA_ATTR int weatherIntervalCounter = -1;
RTC_DATA_ATTR bool displayFullInit = true; RTC_DATA_ATTR bool displayFullInit = true;
void Watchy::init(String datetime){ void Watchy::init(String datetime) {
esp_sleep_wakeup_cause_t wakeup_reason; esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause(); //get wake up reason wakeup_reason = esp_sleep_get_wakeup_cause(); // get wake up reason
Wire.begin(SDA, SCL); //init i2c Wire.begin(SDA, SCL); // init i2c
RTC.init(); RTC.init();
// Init the display here for all cases, if unused, it will do nothing // Init the display here for all cases, if unused, it will do nothing
display.init(0, displayFullInit, 10, true); // 10ms by spec, and fast pulldown reset display.init(0, displayFullInit, 10,
true); // 10ms by spec, and fast pulldown reset
display.epd2.setBusyCallback(displayBusyCallback); display.epd2.setBusyCallback(displayBusyCallback);
switch (wakeup_reason) switch (wakeup_reason) {
{ case ESP_SLEEP_WAKEUP_EXT0: // RTC Alarm
case ESP_SLEEP_WAKEUP_EXT0: //RTC Alarm if (guiState == WATCHFACE_STATE) {
if(guiState == WATCHFACE_STATE){
RTC.read(currentTime); RTC.read(currentTime);
showWatchFace(true); //partial updates on tick showWatchFace(true); // partial updates on tick
} }
break; break;
case ESP_SLEEP_WAKEUP_EXT1: //button Press case ESP_SLEEP_WAKEUP_EXT1: // button Press
handleButtonPress(); handleButtonPress();
break; break;
default: //reset default: // reset
RTC.config(datetime); RTC.config(datetime);
_bmaConfig(); _bmaConfig();
RTC.read(currentTime); RTC.read(currentTime);
showWatchFace(false); //full update on reset showWatchFace(false); // full update on reset
break; break;
} }
deepSleep(); deepSleep();
} }
void Watchy::displayBusyCallback(const void*){ void Watchy::displayBusyCallback(const void *) {
gpio_wakeup_enable((gpio_num_t)DISPLAY_BUSY, GPIO_INTR_LOW_LEVEL); gpio_wakeup_enable((gpio_num_t)DISPLAY_BUSY, GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup(); esp_sleep_enable_gpio_wakeup();
esp_light_sleep_start(); esp_light_sleep_start();
} }
void Watchy::deepSleep(){ void Watchy::deepSleep() {
display.hibernate(); display.hibernate();
displayFullInit = false; // Notify not to init it again displayFullInit = false; // Notify not to init it again
RTC.clearAlarm(); //resets the alarm flag in the RTC RTC.clearAlarm(); // resets the alarm flag in the RTC
// Set pins 0-39 to input to avoid power leaking out // Set pins 0-39 to input to avoid power leaking out
for(int i=0; i<40; i++) { for (int i = 0; i < 40; i++) {
pinMode(i, INPUT); pinMode(i, INPUT);
} }
esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN, 0); //enable deep sleep wake on RTC interrupt esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN,
esp_sleep_enable_ext1_wakeup(BTN_PIN_MASK, ESP_EXT1_WAKEUP_ANY_HIGH); //enable deep sleep wake on button press 0); // enable deep sleep wake on RTC interrupt
esp_sleep_enable_ext1_wakeup(
BTN_PIN_MASK,
ESP_EXT1_WAKEUP_ANY_HIGH); // enable deep sleep wake on button press
esp_deep_sleep_start(); esp_deep_sleep_start();
} }
void Watchy::handleButtonPress(){ void Watchy::handleButtonPress() {
uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status(); uint64_t wakeupBit = esp_sleep_get_ext1_wakeup_status();
//Menu Button // Menu Button
if (wakeupBit & MENU_BTN_MASK){ if (wakeupBit & MENU_BTN_MASK) {
if(guiState == WATCHFACE_STATE){//enter menu state if coming from watch face if (guiState ==
WATCHFACE_STATE) { // enter menu state if coming from watch face
showMenu(menuIndex, false); showMenu(menuIndex, false);
}else if(guiState == MAIN_MENU_STATE){//if already in menu, then select menu item } else if (guiState ==
switch(menuIndex) MAIN_MENU_STATE) { // if already in menu, then select menu item
{ switch (menuIndex) {
case 0: case 0:
showAbout(); showAbout();
break; break;
@ -95,44 +100,44 @@ void Watchy::handleButtonPress(){
default: default:
break; break;
} }
}else if(guiState == FW_UPDATE_STATE){ } else if (guiState == FW_UPDATE_STATE) {
updateFWBegin(); updateFWBegin();
} }
} }
//Back Button // Back Button
else if (wakeupBit & BACK_BTN_MASK){ else if (wakeupBit & BACK_BTN_MASK) {
if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu if (guiState == MAIN_MENU_STATE) { // exit to watch face if already in menu
RTC.read(currentTime); RTC.read(currentTime);
showWatchFace(false); showWatchFace(false);
}else if(guiState == APP_STATE){ } else if (guiState == APP_STATE) {
showMenu(menuIndex, false);//exit to menu if already in app showMenu(menuIndex, false); // exit to menu if already in app
}else if(guiState == FW_UPDATE_STATE){ } else if (guiState == FW_UPDATE_STATE) {
showMenu(menuIndex, false);//exit to menu if already in app showMenu(menuIndex, false); // exit to menu if already in app
}else if(guiState == WATCHFACE_STATE){ } else if (guiState == WATCHFACE_STATE) {
return; return;
} }
} }
//Up Button // Up Button
else if (wakeupBit & UP_BTN_MASK){ else if (wakeupBit & UP_BTN_MASK) {
if(guiState == MAIN_MENU_STATE){//increment menu index if (guiState == MAIN_MENU_STATE) { // increment menu index
menuIndex--; menuIndex--;
if(menuIndex < 0){ if (menuIndex < 0) {
menuIndex = MENU_LENGTH - 1; menuIndex = MENU_LENGTH - 1;
} }
showMenu(menuIndex, true); showMenu(menuIndex, true);
}else if(guiState == WATCHFACE_STATE){ } else if (guiState == WATCHFACE_STATE) {
return; return;
} }
} }
//Down Button // Down Button
else if (wakeupBit & DOWN_BTN_MASK){ else if (wakeupBit & DOWN_BTN_MASK) {
if(guiState == MAIN_MENU_STATE){//decrement menu index if (guiState == MAIN_MENU_STATE) { // decrement menu index
menuIndex++; menuIndex++;
if(menuIndex > MENU_LENGTH - 1){ if (menuIndex > MENU_LENGTH - 1) {
menuIndex = 0; menuIndex = 0;
} }
showMenu(menuIndex, true); showMenu(menuIndex, true);
}else if(guiState == WATCHFACE_STATE){ } else if (guiState == WATCHFACE_STATE) {
return; return;
} }
} }
@ -144,15 +149,15 @@ void Watchy::handleButtonPress(){
pinMode(BACK_BTN_PIN, INPUT); pinMode(BACK_BTN_PIN, INPUT);
pinMode(UP_BTN_PIN, INPUT); pinMode(UP_BTN_PIN, INPUT);
pinMode(DOWN_BTN_PIN, INPUT); pinMode(DOWN_BTN_PIN, INPUT);
while(!timeout){ while (!timeout) {
if(millis() - lastTimeout > 5000){ if (millis() - lastTimeout > 5000) {
timeout = true; timeout = true;
}else{ } else {
if(digitalRead(MENU_BTN_PIN) == 1){ if (digitalRead(MENU_BTN_PIN) == 1) {
lastTimeout = millis(); lastTimeout = millis();
if(guiState == MAIN_MENU_STATE){//if already in menu, then select menu item if (guiState ==
switch(menuIndex) MAIN_MENU_STATE) { // if already in menu, then select menu item
{ switch (menuIndex) {
case 0: case 0:
showAbout(); showAbout();
break; break;
@ -177,34 +182,35 @@ void Watchy::handleButtonPress(){
default: default:
break; break;
} }
}else if(guiState == FW_UPDATE_STATE){ } else if (guiState == FW_UPDATE_STATE) {
updateFWBegin(); updateFWBegin();
} }
}else if(digitalRead(BACK_BTN_PIN) == 1){ } else if (digitalRead(BACK_BTN_PIN) == 1) {
lastTimeout = millis(); lastTimeout = millis();
if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu if (guiState ==
MAIN_MENU_STATE) { // exit to watch face if already in menu
RTC.read(currentTime); RTC.read(currentTime);
showWatchFace(false); showWatchFace(false);
break; //leave loop break; // leave loop
}else if(guiState == APP_STATE){ } else if (guiState == APP_STATE) {
showMenu(menuIndex, false);//exit to menu if already in app showMenu(menuIndex, false); // exit to menu if already in app
}else if(guiState == FW_UPDATE_STATE){ } else if (guiState == FW_UPDATE_STATE) {
showMenu(menuIndex, false);//exit to menu if already in app showMenu(menuIndex, false); // exit to menu if already in app
} }
}else if(digitalRead(UP_BTN_PIN) == 1){ } else if (digitalRead(UP_BTN_PIN) == 1) {
lastTimeout = millis(); lastTimeout = millis();
if(guiState == MAIN_MENU_STATE){//increment menu index if (guiState == MAIN_MENU_STATE) { // increment menu index
menuIndex--; menuIndex--;
if(menuIndex < 0){ if (menuIndex < 0) {
menuIndex = MENU_LENGTH - 1; menuIndex = MENU_LENGTH - 1;
} }
showFastMenu(menuIndex); showFastMenu(menuIndex);
} }
}else if(digitalRead(DOWN_BTN_PIN) == 1){ } else if (digitalRead(DOWN_BTN_PIN) == 1) {
lastTimeout = millis(); lastTimeout = millis();
if(guiState == MAIN_MENU_STATE){//decrement menu index if (guiState == MAIN_MENU_STATE) { // decrement menu index
menuIndex++; menuIndex++;
if(menuIndex > MENU_LENGTH - 1){ if (menuIndex > MENU_LENGTH - 1) {
menuIndex = 0; menuIndex = 0;
} }
showFastMenu(menuIndex); showFastMenu(menuIndex);
@ -214,7 +220,7 @@ void Watchy::handleButtonPress(){
} }
} }
void Watchy::showMenu(byte menuIndex, bool partialRefresh){ void Watchy::showMenu(byte menuIndex, bool partialRefresh) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -223,16 +229,19 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh){
uint16_t w, h; uint16_t w, h;
int16_t yPos; int16_t yPos;
const char *menuItems[] = {"About Watchy", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware", "Sync NTP"}; const char *menuItems[] = {
for(int i=0; i<MENU_LENGTH; i++){ "About Watchy", "Vibrate Motor", "Show Accelerometer",
yPos = MENU_HEIGHT+(MENU_HEIGHT*i); "Set Time", "Setup WiFi", "Update Firmware",
"Sync NTP"};
for (int i = 0; i < MENU_LENGTH; i++) {
yPos = MENU_HEIGHT + (MENU_HEIGHT * i);
display.setCursor(0, yPos); display.setCursor(0, yPos);
if(i == menuIndex){ if (i == menuIndex) {
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h); display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE); display.fillRect(x1 - 1, y1 - 10, 200, h + 15, GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK); display.setTextColor(GxEPD_BLACK);
display.println(menuItems[i]); display.println(menuItems[i]);
}else{ } else {
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.println(menuItems[i]); display.println(menuItems[i]);
} }
@ -243,7 +252,7 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh){
guiState = MAIN_MENU_STATE; guiState = MAIN_MENU_STATE;
} }
void Watchy::showFastMenu(byte menuIndex){ void Watchy::showFastMenu(byte menuIndex) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -252,16 +261,19 @@ void Watchy::showFastMenu(byte menuIndex){
uint16_t w, h; uint16_t w, h;
int16_t yPos; int16_t yPos;
const char *menuItems[] = {"About Watchy", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware", "Sync NTP"}; const char *menuItems[] = {
for(int i=0; i<MENU_LENGTH; i++){ "About Watchy", "Vibrate Motor", "Show Accelerometer",
yPos = MENU_HEIGHT+(MENU_HEIGHT*i); "Set Time", "Setup WiFi", "Update Firmware",
"Sync NTP"};
for (int i = 0; i < MENU_LENGTH; i++) {
yPos = MENU_HEIGHT + (MENU_HEIGHT * i);
display.setCursor(0, yPos); display.setCursor(0, yPos);
if(i == menuIndex){ if (i == menuIndex) {
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h); display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
display.fillRect(x1-1, y1-10, 200, h+15, GxEPD_WHITE); display.fillRect(x1 - 1, y1 - 10, 200, h + 15, GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK); display.setTextColor(GxEPD_BLACK);
display.println(menuItems[i]); display.println(menuItems[i]);
}else{ } else {
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.println(menuItems[i]); display.println(menuItems[i]);
} }
@ -272,7 +284,7 @@ void Watchy::showFastMenu(byte menuIndex){
guiState = MAIN_MENU_STATE; guiState = MAIN_MENU_STATE;
} }
void Watchy::showAbout(){ void Watchy::showAbout() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -282,43 +294,43 @@ void Watchy::showAbout(){
display.print("LibVer: "); display.print("LibVer: ");
display.println(WATCHY_LIB_VER); display.println(WATCHY_LIB_VER);
const char *RTC_HW[3] = { "<UNKNOWN>", "DS3231", "PCF8563" }; const char *RTC_HW[3] = {"<UNKNOWN>", "DS3231", "PCF8563"};
display.print("RTC: "); display.print("RTC: ");
display.println(RTC_HW[RTC.rtcType]); //0 = UNKNOWN, 1 = DS3231, 2 = PCF8563 display.println(RTC_HW[RTC.rtcType]); // 0 = UNKNOWN, 1 = DS3231, 2 = PCF8563
display.print("Batt: "); display.print("Batt: ");
float voltage = getBatteryVoltage(); float voltage = getBatteryVoltage();
display.print(voltage); display.print(voltage);
display.println("V"); display.println("V");
display.display(false); //full refresh display.display(false); // full refresh
guiState = APP_STATE; guiState = APP_STATE;
} }
void Watchy::showBuzz(){ void Watchy::showBuzz() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.setCursor(70, 80); display.setCursor(70, 80);
display.println("Buzz!"); display.println("Buzz!");
display.display(false); //full refresh display.display(false); // full refresh
vibMotor(); vibMotor();
showMenu(menuIndex, false); showMenu(menuIndex, false);
} }
void Watchy::vibMotor(uint8_t intervalMs, uint8_t length){ void Watchy::vibMotor(uint8_t intervalMs, uint8_t length) {
pinMode(VIB_MOTOR_PIN, OUTPUT); pinMode(VIB_MOTOR_PIN, OUTPUT);
bool motorOn = false; bool motorOn = false;
for(int i=0; i<length; i++){ for (int i = 0; i < length; i++) {
motorOn = !motorOn; motorOn = !motorOn;
digitalWrite(VIB_MOTOR_PIN, motorOn); digitalWrite(VIB_MOTOR_PIN, motorOn);
delay(intervalMs); delay(intervalMs);
} }
} }
void Watchy::setTime(){ void Watchy::setTime() {
guiState = APP_STATE; guiState = APP_STATE;
@ -341,25 +353,25 @@ void Watchy::setTime(){
display.setFullWindow(); display.setFullWindow();
while(1){ while (1) {
if(digitalRead(MENU_BTN_PIN) == 1){ if (digitalRead(MENU_BTN_PIN) == 1) {
setIndex++; setIndex++;
if(setIndex > SET_DAY){ if (setIndex > SET_DAY) {
break; break;
} }
} }
if(digitalRead(BACK_BTN_PIN) == 1){ if (digitalRead(BACK_BTN_PIN) == 1) {
if(setIndex != SET_HOUR){ if (setIndex != SET_HOUR) {
setIndex--; setIndex--;
} }
} }
blink = 1 - blink; blink = 1 - blink;
if(digitalRead(DOWN_BTN_PIN) == 1){ if (digitalRead(DOWN_BTN_PIN) == 1) {
blink = 1; blink = 1;
switch(setIndex){ switch (setIndex) {
case SET_HOUR: case SET_HOUR:
hour == 23 ? (hour = 0) : hour++; hour == 23 ? (hour = 0) : hour++;
break; break;
@ -380,9 +392,9 @@ void Watchy::setTime(){
} }
} }
if(digitalRead(UP_BTN_PIN) == 1){ if (digitalRead(UP_BTN_PIN) == 1) {
blink = 1; blink = 1;
switch(setIndex){ switch (setIndex) {
case SET_HOUR: case SET_HOUR:
hour == 0 ? (hour = 23) : hour--; hour == 0 ? (hour = 23) : hour--;
break; break;
@ -408,10 +420,10 @@ void Watchy::setTime(){
display.setFont(&DSEG7_Classic_Bold_53); display.setFont(&DSEG7_Classic_Bold_53);
display.setCursor(5, 80); display.setCursor(5, 80);
if(setIndex == SET_HOUR){//blink hour digits if (setIndex == SET_HOUR) { // blink hour digits
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK); display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
} }
if(hour < 10){ if (hour < 10) {
display.print("0"); display.print("0");
} }
display.print(hour); display.print(hour);
@ -420,10 +432,10 @@ void Watchy::setTime(){
display.print(":"); display.print(":");
display.setCursor(108, 80); display.setCursor(108, 80);
if(setIndex == SET_MINUTE){//blink minute digits if (setIndex == SET_MINUTE) { // blink minute digits
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK); display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
} }
if(minute < 10){ if (minute < 10) {
display.print("0"); display.print("0");
} }
display.print(minute); display.print(minute);
@ -432,18 +444,18 @@ void Watchy::setTime(){
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
display.setCursor(45, 150); display.setCursor(45, 150);
if(setIndex == SET_YEAR){//blink minute digits if (setIndex == SET_YEAR) { // blink minute digits
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK); display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
} }
display.print(2000+year); display.print(2000 + year);
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.print("/"); display.print("/");
if(setIndex == SET_MONTH){//blink minute digits if (setIndex == SET_MONTH) { // blink minute digits
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK); display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
} }
if(month < 10){ if (month < 10) {
display.print("0"); display.print("0");
} }
display.print(month); display.print(month);
@ -451,14 +463,14 @@ void Watchy::setTime(){
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.print("/"); display.print("/");
if(setIndex == SET_DAY){//blink minute digits if (setIndex == SET_DAY) { // blink minute digits
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK); display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
} }
if(day < 10){ if (day < 10) {
display.print("0"); display.print("0");
} }
display.print(day); display.print(day);
display.display(true); //partial refresh display.display(true); // partial refresh
} }
tmElements_t tm; tmElements_t tm;
@ -472,10 +484,9 @@ void Watchy::setTime(){
RTC.set(tm); RTC.set(tm);
showMenu(menuIndex, false); showMenu(menuIndex, false);
} }
void Watchy::showAccelerometer(){ void Watchy::showAccelerometer() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -490,30 +501,33 @@ void Watchy::showAccelerometer(){
pinMode(BACK_BTN_PIN, INPUT); pinMode(BACK_BTN_PIN, INPUT);
while(1){ while (1) {
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
if(digitalRead(BACK_BTN_PIN) == 1){ if (digitalRead(BACK_BTN_PIN) == 1) {
break; break;
} }
if(currentMillis - previousMillis > interval){ if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis; previousMillis = currentMillis;
// Get acceleration data // Get acceleration data
bool res = sensor.getAccel(acc); bool res = sensor.getAccel(acc);
uint8_t direction = sensor.getDirection(); uint8_t direction = sensor.getDirection();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setCursor(0, 30); display.setCursor(0, 30);
if(res == false) { if (res == false) {
display.println("getAccel FAIL"); display.println("getAccel FAIL");
}else{ } else {
display.print(" X:"); display.println(acc.x); display.print(" X:");
display.print(" Y:"); display.println(acc.y); display.println(acc.x);
display.print(" Z:"); display.println(acc.z); display.print(" Y:");
display.println(acc.y);
display.print(" Z:");
display.println(acc.z);
display.setCursor(30, 130); display.setCursor(30, 130);
switch(direction){ switch (direction) {
case DIRECTION_DISP_DOWN: case DIRECTION_DISP_DOWN:
display.println("FACE DOWN"); display.println("FACE DOWN");
break; break;
@ -536,90 +550,100 @@ void Watchy::showAccelerometer(){
display.println("ERROR!!!"); display.println("ERROR!!!");
break; break;
} }
} }
display.display(true); //full refresh display.display(true); // full refresh
} }
} }
showMenu(menuIndex, false); showMenu(menuIndex, false);
} }
void Watchy::showWatchFace(bool partialRefresh){ void Watchy::showWatchFace(bool partialRefresh) {
display.setFullWindow(); display.setFullWindow();
drawWatchFace(); drawWatchFace();
display.display(partialRefresh); //partial refresh display.display(partialRefresh); // partial refresh
guiState = WATCHFACE_STATE; guiState = WATCHFACE_STATE;
} }
void Watchy::drawWatchFace(){ void Watchy::drawWatchFace() {
display.setFont(&DSEG7_Classic_Bold_53); display.setFont(&DSEG7_Classic_Bold_53);
display.setCursor(5, 53+60); display.setCursor(5, 53 + 60);
if(currentTime.Hour < 10){ if (currentTime.Hour < 10) {
display.print("0"); display.print("0");
} }
display.print(currentTime.Hour); display.print(currentTime.Hour);
display.print(":"); display.print(":");
if(currentTime.Minute < 10){ if (currentTime.Minute < 10) {
display.print("0"); display.print("0");
} }
display.println(currentTime.Minute); display.println(currentTime.Minute);
} }
weatherData Watchy::getWeatherData(){ weatherData Watchy::getWeatherData() {
return getWeatherData(settings.cityID, settings.weatherUnit, settings.weatherLang, settings.weatherURL, settings.weatherAPIKey, settings.weatherUpdateInterval); return getWeatherData(settings.cityID, settings.weatherUnit,
settings.weatherLang, settings.weatherURL,
settings.weatherAPIKey, settings.weatherUpdateInterval);
} }
weatherData Watchy::getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval){ weatherData Watchy::getWeatherData(String cityID, String units, String lang,
String url, String apiKey,
uint8_t updateInterval) {
currentWeather.isMetric = units == String("metric"); currentWeather.isMetric = units == String("metric");
if(weatherIntervalCounter < 0){ //-1 on first run, set to updateInterval if (weatherIntervalCounter < 0) { //-1 on first run, set to updateInterval
weatherIntervalCounter = updateInterval; weatherIntervalCounter = updateInterval;
} }
if(weatherIntervalCounter >= updateInterval){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes if (weatherIntervalCounter >=
if(connectWiFi()){ updateInterval) { // only update if WEATHER_UPDATE_INTERVAL has elapsed
HTTPClient http; //Use Weather API for live data if WiFi is connected // i.e. 30 minutes
http.setConnectTimeout(3000);//3 second max timeout if (connectWiFi()) {
String weatherQueryURL = url + cityID + String("&units=") + units + String("&lang=") + lang + String("&appid=") + apiKey; HTTPClient http; // Use Weather API for live data if WiFi is connected
http.setConnectTimeout(3000); // 3 second max timeout
String weatherQueryURL = url + cityID + String("&units=") + units +
String("&lang=") + lang + String("&appid=") +
apiKey;
http.begin(weatherQueryURL.c_str()); http.begin(weatherQueryURL.c_str());
int httpResponseCode = http.GET(); int httpResponseCode = http.GET();
if(httpResponseCode == 200) { if (httpResponseCode == 200) {
String payload = http.getString(); String payload = http.getString();
JSONVar responseObject = JSON.parse(payload); JSONVar responseObject = JSON.parse(payload);
currentWeather.temperature = int(responseObject["main"]["temp"]); currentWeather.temperature = int(responseObject["main"]["temp"]);
currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]); currentWeather.weatherConditionCode =
currentWeather.weatherDescription = responseObject["weather"][0]["main"]; int(responseObject["weather"][0]["id"]);
}else{ currentWeather.weatherDescription =
//http error responseObject["weather"][0]["main"];
} else {
// http error
} }
http.end(); http.end();
//turn off radios // turn off radios
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
btStop(); btStop();
}else{//No WiFi, use internal temperature sensor } else { // No WiFi, use internal temperature sensor
uint8_t temperature = sensor.readTemperature(); //celsius uint8_t temperature = sensor.readTemperature(); // celsius
if(!currentWeather.isMetric){ if (!currentWeather.isMetric) {
temperature = temperature * 9. / 5. + 32.; //fahrenheit temperature = temperature * 9. / 5. + 32.; // fahrenheit
} }
currentWeather.temperature = temperature; currentWeather.temperature = temperature;
currentWeather.weatherConditionCode = 800; currentWeather.weatherConditionCode = 800;
} }
weatherIntervalCounter = 0; weatherIntervalCounter = 0;
}else{ } else {
weatherIntervalCounter++; weatherIntervalCounter++;
} }
return currentWeather; return currentWeather;
} }
float Watchy::getBatteryVoltage(){ float Watchy::getBatteryVoltage() {
if(RTC.rtcType == DS3231){ if (RTC.rtcType == DS3231) {
return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f * 2.0f; // Battery voltage goes through a 1/2 divider. return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f *
}else{ 2.0f; // Battery voltage goes through a 1/2 divider.
} else {
return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f * 2.0f; return analogReadMilliVolts(BATT_ADC_PIN) / 1000.0f * 2.0f;
} }
} }
uint16_t Watchy::_readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len) uint16_t Watchy::_readRegister(uint8_t address, uint8_t reg, uint8_t *data,
{ uint16_t len) {
Wire.beginTransmission(address); Wire.beginTransmission(address);
Wire.write(reg); Wire.write(reg);
Wire.endTransmission(); Wire.endTransmission();
@ -631,18 +655,18 @@ uint16_t Watchy::_readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint
return 0; return 0;
} }
uint16_t Watchy::_writeRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len) uint16_t Watchy::_writeRegister(uint8_t address, uint8_t reg, uint8_t *data,
{ uint16_t len) {
Wire.beginTransmission(address); Wire.beginTransmission(address);
Wire.write(reg); Wire.write(reg);
Wire.write(data, len); Wire.write(data, len);
return (0 != Wire.endTransmission()); return (0 != Wire.endTransmission());
} }
void Watchy::_bmaConfig(){ void Watchy::_bmaConfig() {
if (sensor.begin(_readRegister, _writeRegister, delay) == false) { if (sensor.begin(_readRegister, _writeRegister, delay) == false) {
//fail to init BMA // fail to init BMA
return; return;
} }
@ -699,7 +723,7 @@ void Watchy::_bmaConfig(){
// Warning : Need to use feature, you must first enable the accelerometer // Warning : Need to use feature, you must first enable the accelerometer
sensor.enableAccel(); sensor.enableAccel();
struct bma4_int_pin_config config ; struct bma4_int_pin_config config;
config.edge_ctrl = BMA4_LEVEL_TRIGGER; config.edge_ctrl = BMA4_LEVEL_TRIGGER;
config.lvl = BMA4_ACTIVE_HIGH; config.lvl = BMA4_ACTIVE_HIGH;
config.od = BMA4_PUSH_PULL; config.od = BMA4_PUSH_PULL;
@ -735,8 +759,8 @@ void Watchy::_bmaConfig(){
sensor.enableWakeupInterrupt(); sensor.enableWakeupInterrupt();
} }
void Watchy::setupWifi(){ void Watchy::setupWifi() {
display.epd2.setBusyCallback(0); //temporarily disable lightsleep on busy display.epd2.setBusyCallback(0); // temporarily disable lightsleep on busy
WiFiManager wifiManager; WiFiManager wifiManager;
wifiManager.resetSettings(); wifiManager.resetSettings();
wifiManager.setTimeout(WIFI_AP_TIMEOUT); wifiManager.setTimeout(WIFI_AP_TIMEOUT);
@ -745,22 +769,23 @@ void Watchy::setupWifi(){
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
if(!wifiManager.autoConnect(WIFI_AP_SSID)) {//WiFi setup failed if (!wifiManager.autoConnect(WIFI_AP_SSID)) { // WiFi setup failed
display.println("Setup failed &"); display.println("Setup failed &");
display.println("timed out!"); display.println("timed out!");
}else{ } else {
display.println("Connected to"); display.println("Connected to");
display.println(WiFi.SSID()); display.println(WiFi.SSID());
} }
display.display(false); //full refresh display.display(false); // full refresh
//turn off radios // turn off radios
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
btStop(); btStop();
display.epd2.setBusyCallback(displayBusyCallback); //enable lightsleep on busy display.epd2.setBusyCallback(displayBusyCallback); // enable lightsleep on
// busy
guiState = APP_STATE; guiState = APP_STATE;
} }
void Watchy::_configModeCallback (WiFiManager *myWiFiManager) { void Watchy::_configModeCallback(WiFiManager *myWiFiManager) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -771,18 +796,21 @@ void Watchy::_configModeCallback (WiFiManager *myWiFiManager) {
display.println(WIFI_AP_SSID); display.println(WIFI_AP_SSID);
display.print("IP: "); display.print("IP: ");
display.println(WiFi.softAPIP()); display.println(WiFi.softAPIP());
display.display(false); //full refresh display.display(false); // full refresh
} }
bool Watchy::connectWiFi(){ bool Watchy::connectWiFi() {
if(WL_CONNECT_FAILED == WiFi.begin()){//WiFi not setup, you can also use hard coded credentials with WiFi.begin(SSID,PASS); if (WL_CONNECT_FAILED ==
WiFi.begin()) { // WiFi not setup, you can also use hard coded credentials
// with WiFi.begin(SSID,PASS);
WIFI_CONFIGURED = false; WIFI_CONFIGURED = false;
}else{ } else {
if(WL_CONNECTED == WiFi.waitForConnectResult()){//attempt to connect for 10s if (WL_CONNECTED ==
WiFi.waitForConnectResult()) { // attempt to connect for 10s
WIFI_CONFIGURED = true; WIFI_CONFIGURED = true;
}else{//connection failed, time out } else { // connection failed, time out
WIFI_CONFIGURED = false; WIFI_CONFIGURED = false;
//turn off radios // turn off radios
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
btStop(); btStop();
} }
@ -790,7 +818,7 @@ bool Watchy::connectWiFi(){
return WIFI_CONFIGURED; return WIFI_CONFIGURED;
} }
void Watchy::showUpdateFW(){ void Watchy::showUpdateFW() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -805,12 +833,12 @@ void Watchy::showUpdateFW(){
display.println("again when ready"); display.println("again when ready");
display.println(" "); display.println(" ");
display.println("Keep USB powered"); display.println("Keep USB powered");
display.display(false); //full refresh display.display(false); // full refresh
guiState = FW_UPDATE_STATE; guiState = FW_UPDATE_STATE;
} }
void Watchy::updateFWBegin(){ void Watchy::updateFWBegin() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -822,17 +850,17 @@ void Watchy::updateFWBegin(){
display.println(" "); display.println(" ");
display.println("Waiting for"); display.println("Waiting for");
display.println("connection..."); display.println("connection...");
display.display(false); //full refresh display.display(false); // full refresh
BLE BT; BLE BT;
BT.begin("Watchy BLE OTA"); BT.begin("Watchy BLE OTA");
int prevStatus = -1; int prevStatus = -1;
int currentStatus; int currentStatus;
while(1){ while (1) {
currentStatus = BT.updateStatus(); currentStatus = BT.updateStatus();
if(prevStatus != currentStatus || prevStatus == 1){ if (prevStatus != currentStatus || prevStatus == 1) {
if(currentStatus == 0){ if (currentStatus == 0) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -842,9 +870,9 @@ void Watchy::updateFWBegin(){
display.println(" "); display.println(" ");
display.println("Waiting for"); display.println("Waiting for");
display.println("upload..."); display.println("upload...");
display.display(false); //full refresh display.display(false); // full refresh
} }
if(currentStatus == 1){ if (currentStatus == 1) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -855,9 +883,9 @@ void Watchy::updateFWBegin(){
display.println(" "); display.println(" ");
display.print(BT.howManyBytes()); display.print(BT.howManyBytes());
display.println(" bytes"); display.println(" bytes");
display.display(true); //partial refresh display.display(true); // partial refresh
} }
if(currentStatus == 2){ if (currentStatus == 2) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -867,12 +895,12 @@ void Watchy::updateFWBegin(){
display.println("completed!"); display.println("completed!");
display.println(" "); display.println(" ");
display.println("Rebooting..."); display.println("Rebooting...");
display.display(false); //full refresh display.display(false); // full refresh
delay(2000); delay(2000);
esp_restart(); esp_restart();
} }
if(currentStatus == 4){ if (currentStatus == 4) {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
@ -881,7 +909,7 @@ void Watchy::updateFWBegin(){
display.println("BLE Disconnected!"); display.println("BLE Disconnected!");
display.println(" "); display.println(" ");
display.println("exiting..."); display.println("exiting...");
display.display(false); //full refresh display.display(false); // full refresh
delay(1000); delay(1000);
break; break;
} }
@ -890,22 +918,22 @@ void Watchy::updateFWBegin(){
delay(100); delay(100);
} }
//turn off radios // turn off radios
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
btStop(); btStop();
showMenu(menuIndex, false); showMenu(menuIndex, false);
} }
void Watchy::showSyncNTP(){ void Watchy::showSyncNTP() {
display.setFullWindow(); display.setFullWindow();
display.fillScreen(GxEPD_BLACK); display.fillScreen(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b); display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_WHITE); display.setTextColor(GxEPD_WHITE);
display.setCursor(0, 30); display.setCursor(0, 30);
display.println("Syncing NTP... "); display.println("Syncing NTP... ");
display.display(false); //full refresh display.display(false); // full refresh
if(connectWiFi()){ if (connectWiFi()) {
if(syncNTP()){ if (syncNTP()) {
display.println("NTP Sync Success\n"); display.println("NTP Sync Success\n");
display.println("Current Time Is:"); display.println("Current Time Is:");
@ -918,36 +946,40 @@ void Watchy::showSyncNTP(){
display.print(currentTime.Day); display.print(currentTime.Day);
display.print(" - "); display.print(" - ");
if(currentTime.Hour < 10){ if (currentTime.Hour < 10) {
display.print("0"); display.print("0");
} }
display.print(currentTime.Hour); display.print(currentTime.Hour);
display.print(":"); display.print(":");
if(currentTime.Minute < 10){ if (currentTime.Minute < 10) {
display.print("0"); display.print("0");
} }
display.println(currentTime.Minute); display.println(currentTime.Minute);
}else{ } else {
display.println("NTP Sync Failed"); display.println("NTP Sync Failed");
} }
}else{ } else {
display.println("WiFi Not Configured"); display.println("WiFi Not Configured");
} }
display.display(true); //full refresh display.display(true); // full refresh
delay(3000); delay(3000);
showMenu(menuIndex, false); showMenu(menuIndex, false);
} }
bool Watchy::syncNTP(){ //NTP sync - call after connecting to WiFi and remember to turn it back off bool Watchy::syncNTP() { // NTP sync - call after connecting to WiFi and
return syncNTP(settings.gmtOffset, settings.dstOffset, settings.ntpServer.c_str()); // remember to turn it back off
return syncNTP(settings.gmtOffset, settings.dstOffset,
settings.ntpServer.c_str());
} }
bool Watchy::syncNTP(long gmt, int dst, String ntpServer){ //NTP sync - call after connecting to WiFi and remember to turn it back off bool Watchy::syncNTP(long gmt, int dst,
String ntpServer) { // NTP sync - call after connecting to
// WiFi and remember to turn it back off
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServer.c_str(), gmt); NTPClient timeClient(ntpUDP, ntpServer.c_str(), gmt);
timeClient.begin(); timeClient.begin();
if(!timeClient.forceUpdate()){ if (!timeClient.forceUpdate()) {
return false; //NTP sync failed return false; // NTP sync failed
} }
tmElements_t tm; tmElements_t tm;
breakTime((time_t)timeClient.getEpochTime(), tm); breakTime((time_t)timeClient.getEpochTime(), tm);

View File

@ -1,53 +1,54 @@
#ifndef WATCHY_H #ifndef WATCHY_H
#define WATCHY_H #define WATCHY_H
#include <Arduino.h> #include "BLE.h"
#include <WiFiManager.h>
#include <HTTPClient.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <Arduino_JSON.h>
#include <GxEPD2_BW.h>
#include <Wire.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "DSEG7_Classic_Bold_53.h" #include "DSEG7_Classic_Bold_53.h"
#include "WatchyRTC.h" #include "WatchyRTC.h"
#include "BLE.h"
#include "bma.h" #include "bma.h"
#include "config.h" #include "config.h"
#include <Arduino.h>
#include <Arduino_JSON.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <GxEPD2_BW.h>
#include <HTTPClient.h>
#include <NTPClient.h>
#include <WiFiManager.h>
#include <WiFiUdp.h>
#include <Wire.h>
typedef struct weatherData{ typedef struct weatherData {
int8_t temperature; int8_t temperature;
int16_t weatherConditionCode; int16_t weatherConditionCode;
bool isMetric; bool isMetric;
String weatherDescription; String weatherDescription;
}weatherData; } weatherData;
typedef struct watchySettings{ typedef struct watchySettings {
//Weather Settings // Weather Settings
String cityID; String cityID;
String weatherAPIKey; String weatherAPIKey;
String weatherURL; String weatherURL;
String weatherUnit; String weatherUnit;
String weatherLang; String weatherLang;
int8_t weatherUpdateInterval; int8_t weatherUpdateInterval;
//NTP Settings // NTP Settings
String ntpServer; String ntpServer;
int gmtOffset; int gmtOffset;
int dstOffset; int dstOffset;
}watchySettings; } watchySettings;
class Watchy { class Watchy {
public: public:
static WatchyRTC RTC; static WatchyRTC RTC;
static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display; static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display;
tmElements_t currentTime; tmElements_t currentTime;
watchySettings settings; watchySettings settings;
public:
explicit Watchy(const watchySettings& s) : settings(s){} //constructor public:
explicit Watchy(const watchySettings &s) : settings(s) {} // constructor
void init(String datetime = ""); void init(String datetime = "");
void deepSleep(); void deepSleep();
static void displayBusyCallback(const void*); static void displayBusyCallback(const void *);
float getBatteryVoltage(); float getBatteryVoltage();
void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20); void vibMotor(uint8_t intervalMs = 100, uint8_t length = 20);
@ -65,17 +66,21 @@ class Watchy {
void setupWifi(); void setupWifi();
bool connectWiFi(); bool connectWiFi();
weatherData getWeatherData(); weatherData getWeatherData();
weatherData getWeatherData(String cityID, String units, String lang, String url, String apiKey, uint8_t updateInterval); weatherData getWeatherData(String cityID, String units, String lang,
String url, String apiKey, uint8_t updateInterval);
void updateFWBegin(); void updateFWBegin();
void showWatchFace(bool partialRefresh); void showWatchFace(bool partialRefresh);
virtual void drawWatchFace(); //override this method for different watch faces virtual void drawWatchFace(); // override this method for different watch
// faces
private: private:
void _bmaConfig(); void _bmaConfig();
static void _configModeCallback(WiFiManager *myWiFiManager); static void _configModeCallback(WiFiManager *myWiFiManager);
static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len); static uint16_t _readRegister(uint8_t address, uint8_t reg, uint8_t *data,
static uint16_t _writeRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len); uint16_t len);
static uint16_t _writeRegister(uint8_t address, uint8_t reg, uint8_t *data,
uint16_t len);
}; };
extern RTC_DATA_ATTR int guiState; extern RTC_DATA_ATTR int guiState;

View File

@ -1,86 +1,96 @@
#include "WatchyRTC.h" #include "WatchyRTC.h"
WatchyRTC::WatchyRTC() WatchyRTC::WatchyRTC() : rtc_ds(false) {}
: rtc_ds(false) {}
void WatchyRTC::init(){ void WatchyRTC::init() {
byte error; byte error;
Wire.beginTransmission(RTC_DS_ADDR); Wire.beginTransmission(RTC_DS_ADDR);
error = Wire.endTransmission(); error = Wire.endTransmission();
if(error == 0){ if (error == 0) {
rtcType = DS3231; rtcType = DS3231;
}else{ } else {
Wire.beginTransmission(RTC_PCF_ADDR); Wire.beginTransmission(RTC_PCF_ADDR);
error = Wire.endTransmission(); error = Wire.endTransmission();
if(error == 0){ if (error == 0) {
rtcType = PCF8563; rtcType = PCF8563;
}else{ } else {
//RTC Error // RTC Error
} }
} }
} }
void WatchyRTC::config(String datetime){ //String datetime format is YYYY:MM:DD:HH:MM:SS void WatchyRTC::config(
if(rtcType == DS3231){ String datetime) { // String datetime format is YYYY:MM:DD:HH:MM:SS
if (rtcType == DS3231) {
_DSConfig(datetime); _DSConfig(datetime);
}else{ } else {
_PCFConfig(datetime); _PCFConfig(datetime);
} }
} }
void WatchyRTC::clearAlarm(){ void WatchyRTC::clearAlarm() {
if(rtcType == DS3231){ if (rtcType == DS3231) {
rtc_ds.alarm(DS3232RTC::ALARM_2); rtc_ds.alarm(DS3232RTC::ALARM_2);
}else{ } else {
int nextAlarmMinute = 0; int nextAlarmMinute = 0;
rtc_pcf.clearAlarm(); //resets the alarm flag in the RTC rtc_pcf.clearAlarm(); // resets the alarm flag in the RTC
nextAlarmMinute = rtc_pcf.getMinute(); nextAlarmMinute = rtc_pcf.getMinute();
nextAlarmMinute = (nextAlarmMinute == 59) ? 0 : (nextAlarmMinute + 1); //set alarm to trigger 1 minute from now nextAlarmMinute =
(nextAlarmMinute == 59)
? 0
: (nextAlarmMinute + 1); // set alarm to trigger 1 minute from now
rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99); rtc_pcf.setAlarm(nextAlarmMinute, 99, 99, 99);
} }
} }
void WatchyRTC::read(tmElements_t &tm){ void WatchyRTC::read(tmElements_t &tm) {
if(rtcType == DS3231){ if (rtcType == DS3231) {
rtc_ds.read(tm); rtc_ds.read(tm);
}else{ } else {
tm.Year = y2kYearToTm(rtc_pcf.getYear()); tm.Year = y2kYearToTm(rtc_pcf.getYear());
tm.Month = rtc_pcf.getMonth(); tm.Month = rtc_pcf.getMonth();
tm.Day = rtc_pcf.getDay(); tm.Day = rtc_pcf.getDay();
tm.Wday = rtc_pcf.getWeekday() + 1; //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range tm.Wday =
rtc_pcf.getWeekday() + 1; // TimeLib & DS3231 has Wday range of 1-7, but
// PCF8563 stores day of week in 0-6 range
tm.Hour = rtc_pcf.getHour(); tm.Hour = rtc_pcf.getHour();
tm.Minute = rtc_pcf.getMinute(); tm.Minute = rtc_pcf.getMinute();
tm.Second = rtc_pcf.getSecond(); tm.Second = rtc_pcf.getSecond();
} }
} }
void WatchyRTC::set(tmElements_t tm){ void WatchyRTC::set(tmElements_t tm) {
if(rtcType == DS3231){ if (rtcType == DS3231) {
time_t t = makeTime(tm); time_t t = makeTime(tm);
rtc_ds.set(t); rtc_ds.set(t);
}else{ } else {
time_t t = makeTime(tm); //make and break to calculate tm.Wday time_t t = makeTime(tm); // make and break to calculate tm.Wday
breakTime(t, tm); breakTime(t, tm);
//day, weekday, month, century(1=1900, 0=2000), year(0-99) // day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year)); //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range rtc_pcf.setDate(
//hr, min, sec tm.Day, tm.Wday - 1, tm.Month, 0,
tmYearToY2k(tm.Year)); // TimeLib & DS3231 has Wday range of 1-7, but
// PCF8563 stores day of week in 0-6 range
// hr, min, sec
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second); rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
clearAlarm(); clearAlarm();
} }
} }
uint8_t WatchyRTC::temperature(){ uint8_t WatchyRTC::temperature() {
if(rtcType == DS3231){ if (rtcType == DS3231) {
return rtc_ds.temperature(); return rtc_ds.temperature();
}else{ } else {
return 255; //error return 255; // error
} }
} }
void WatchyRTC::_DSConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:MM:SS void WatchyRTC::_DSConfig(
if(datetime != ""){ String datetime) { // String datetime is YYYY:MM:DD:HH:MM:SS
if (datetime != "") {
tmElements_t tm; tmElements_t tm;
tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); //YYYY - 1970 tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); // YYYY -
// 1970
tm.Month = _getValue(datetime, ':', 1).toInt(); tm.Month = _getValue(datetime, ':', 1).toInt();
tm.Day = _getValue(datetime, ':', 2).toInt(); tm.Day = _getValue(datetime, ':', 2).toInt();
tm.Hour = _getValue(datetime, ':', 3).toInt(); tm.Hour = _getValue(datetime, ':', 3).toInt();
@ -89,45 +99,51 @@ void WatchyRTC::_DSConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:M
time_t t = makeTime(tm); time_t t = makeTime(tm);
rtc_ds.set(t); rtc_ds.set(t);
} }
//https://github.com/JChristensen/DS3232RTC // https://github.com/JChristensen/DS3232RTC
rtc_ds.squareWave(DS3232RTC::SQWAVE_NONE); //disable square wave output rtc_ds.squareWave(DS3232RTC::SQWAVE_NONE); // disable square wave output
rtc_ds.setAlarm(DS3232RTC::ALM2_EVERY_MINUTE, 0, 0, 0, 0); //alarm wakes up Watchy every minute rtc_ds.setAlarm(DS3232RTC::ALM2_EVERY_MINUTE, 0, 0, 0,
rtc_ds.alarmInterrupt(DS3232RTC::ALARM_2, true); //enable alarm interrupt 0); // alarm wakes up Watchy every minute
rtc_ds.alarmInterrupt(DS3232RTC::ALARM_2, true); // enable alarm interrupt
} }
void WatchyRTC::_PCFConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:MM:SS void WatchyRTC::_PCFConfig(
if(datetime != ""){ String datetime) { // String datetime is YYYY:MM:DD:HH:MM:SS
if (datetime != "") {
tmElements_t tm; tmElements_t tm;
tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); //YYYY - 1970 tm.Year = CalendarYrToTm(_getValue(datetime, ':', 0).toInt()); // YYYY -
// 1970
tm.Month = _getValue(datetime, ':', 1).toInt(); tm.Month = _getValue(datetime, ':', 1).toInt();
tm.Day = _getValue(datetime, ':', 2).toInt(); tm.Day = _getValue(datetime, ':', 2).toInt();
tm.Hour = _getValue(datetime, ':', 3).toInt(); tm.Hour = _getValue(datetime, ':', 3).toInt();
tm.Minute = _getValue(datetime, ':', 4).toInt(); tm.Minute = _getValue(datetime, ':', 4).toInt();
tm.Second = _getValue(datetime, ':', 5).toInt(); tm.Second = _getValue(datetime, ':', 5).toInt();
time_t t = makeTime(tm); //make and break to calculate tm.Wday time_t t = makeTime(tm); // make and break to calculate tm.Wday
breakTime(t, tm); breakTime(t, tm);
//day, weekday, month, century(1=1900, 0=2000), year(0-99) // day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc_pcf.setDate(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year)); //TimeLib & DS3231 has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range rtc_pcf.setDate(
//hr, min, sec tm.Day, tm.Wday - 1, tm.Month, 0,
tmYearToY2k(tm.Year)); // TimeLib & DS3231 has Wday range of 1-7, but
// PCF8563 stores day of week in 0-6 range
// hr, min, sec
rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second); rtc_pcf.setTime(tm.Hour, tm.Minute, tm.Second);
} }
//on POR event, PCF8563 sets month to 0, which will give an error since months are 1-12 // on POR event, PCF8563 sets month to 0, which will give an error since
// months are 1-12
clearAlarm(); clearAlarm();
} }
String WatchyRTC::_getValue(String data, char separator, int index) String WatchyRTC::_getValue(String data, char separator, int index) {
{
int found = 0; int found = 0;
int strIndex[] = {0, -1}; int strIndex[] = {0, -1};
int maxIndex = data.length()-1; int maxIndex = data.length() - 1;
for(int i=0; i<=maxIndex && found<=index; i++){ for (int i = 0; i <= maxIndex && found <= index; i++) {
if(data.charAt(i)==separator || i==maxIndex){ if (data.charAt(i) == separator || i == maxIndex) {
found++; found++;
strIndex[0] = strIndex[1]+1; strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i+1 : i; strIndex[1] = (i == maxIndex) ? i + 1 : i;
} }
} }
return found>index ? data.substring(strIndex[0], strIndex[1]) : ""; return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
} }

View File

@ -1,10 +1,10 @@
#ifndef WATCHY_RTC_H #ifndef WATCHY_RTC_H
#define WATCHY_RTC_H #define WATCHY_RTC_H
#include <DS3232RTC.h>
#include <Rtc_Pcf8563.h>
#include "config.h" #include "config.h"
#include "time.h" #include "time.h"
#include <DS3232RTC.h>
#include <Rtc_Pcf8563.h>
#define DS3231 1 #define DS3231 1
#define PCF8563 2 #define PCF8563 2
@ -14,19 +14,21 @@
#define YEAR_OFFSET_PCF 2000 #define YEAR_OFFSET_PCF 2000
class WatchyRTC { class WatchyRTC {
public: public:
DS3232RTC rtc_ds; DS3232RTC rtc_ds;
Rtc_Pcf8563 rtc_pcf; Rtc_Pcf8563 rtc_pcf;
uint8_t rtcType; uint8_t rtcType;
public:
public:
WatchyRTC(); WatchyRTC();
void init(); void init();
void config(String datetime); //String datetime format is YYYY:MM:DD:HH:MM:SS void config(String datetime); // String datetime format is YYYY:MM:DD:HH:MM:SS
void clearAlarm(); void clearAlarm();
void read(tmElements_t &tm); void read(tmElements_t &tm);
void set(tmElements_t tm); void set(tmElements_t tm);
uint8_t temperature(); uint8_t temperature();
private:
private:
void _DSConfig(String datetime); void _DSConfig(String datetime);
void _PCFConfig(String datetime); void _PCFConfig(String datetime);
int _getDayOfWeek(int d, int m, int y); int _getDayOfWeek(int d, int m, int y);

View File

@ -7,28 +7,20 @@
#define DEBUG(...) #define DEBUG(...)
#endif #endif
BMA423::BMA423() BMA423::BMA423() {
{
__readRegisterFptr = nullptr; __readRegisterFptr = nullptr;
__writeRegisterFptr = nullptr; __writeRegisterFptr = nullptr;
__delayCallBlackFptr = nullptr; __delayCallBlackFptr = nullptr;
__init = false; __init = false;
} }
BMA423::~BMA423() BMA423::~BMA423() {}
{
}
bool BMA423::begin(bma4_com_fptr_t readCallBlack, bool BMA423::begin(bma4_com_fptr_t readCallBlack,
bma4_com_fptr_t writeCallBlack, bma4_com_fptr_t writeCallBlack,
bma4_delay_fptr_t delayCallBlack, bma4_delay_fptr_t delayCallBlack, uint8_t address) {
uint8_t address)
{
if (__init || if (__init || readCallBlack == nullptr || writeCallBlack == nullptr ||
readCallBlack == nullptr ||
writeCallBlack == nullptr ||
delayCallBlack == nullptr) { delayCallBlack == nullptr) {
return true; return true;
} }
@ -62,14 +54,13 @@ bool BMA423::begin(bma4_com_fptr_t readCallBlack,
__init = true; __init = true;
struct bma4_int_pin_config config ; struct bma4_int_pin_config config;
config.edge_ctrl = BMA4_LEVEL_TRIGGER; config.edge_ctrl = BMA4_LEVEL_TRIGGER;
config.lvl = BMA4_ACTIVE_HIGH; config.lvl = BMA4_ACTIVE_HIGH;
config.od = BMA4_PUSH_PULL; config.od = BMA4_PUSH_PULL;
config.output_en = BMA4_OUTPUT_ENABLE; config.output_en = BMA4_OUTPUT_ENABLE;
config.input_en = BMA4_INPUT_DISABLE; config.input_en = BMA4_INPUT_DISABLE;
if (bma4_set_int_pin_config(&config, BMA4_INTR1_MAP, &__devFptr) != BMA4_OK) { if (bma4_set_int_pin_config(&config, BMA4_INTR1_MAP, &__devFptr) != BMA4_OK) {
DEBUG("BMA423 SET INT FAIL\n"); DEBUG("BMA423 SET INT FAIL\n");
return false; return false;
@ -77,50 +68,41 @@ bool BMA423::begin(bma4_com_fptr_t readCallBlack,
return true; return true;
} }
void BMA423::softReset() void BMA423::softReset() {
{
uint8_t reg = BMA4_RESET_ADDR; uint8_t reg = BMA4_RESET_ADDR;
__writeRegisterFptr(BMA4_I2C_ADDR_PRIMARY, BMA4_RESET_SET_MASK, &reg, 1); __writeRegisterFptr(BMA4_I2C_ADDR_PRIMARY, BMA4_RESET_SET_MASK, &reg, 1);
} }
void BMA423::shutDown() void BMA423::shutDown() {
{
bma4_set_advance_power_save(BMA4_DISABLE, &__devFptr); bma4_set_advance_power_save(BMA4_DISABLE, &__devFptr);
} }
void BMA423::wakeUp() void BMA423::wakeUp() { bma4_set_advance_power_save(BMA4_ENABLE, &__devFptr); }
{
bma4_set_advance_power_save(BMA4_ENABLE, &__devFptr);
}
uint16_t BMA423::getErrorCode() uint16_t BMA423::getErrorCode() {
{
struct bma4_err_reg err; struct bma4_err_reg err;
uint16_t rslt = bma4_get_error_status(&err, &__devFptr); uint16_t rslt = bma4_get_error_status(&err, &__devFptr);
return rslt; return rslt;
} }
uint16_t BMA423::getStatus() uint16_t BMA423::getStatus() {
{
uint8_t status; uint8_t status;
bma4_get_status(&status, &__devFptr); bma4_get_status(&status, &__devFptr);
return status; return status;
} }
uint32_t BMA423::getSensorTime() uint32_t BMA423::getSensorTime() {
{
uint32_t ms; uint32_t ms;
bma4_get_sensor_time(&ms, &__devFptr); bma4_get_sensor_time(&ms, &__devFptr);
return ms; return ms;
} }
bool BMA423::selfTest() bool BMA423::selfTest() {
{ return (BMA4_OK ==
return (BMA4_OK == bma4_selftest_config(BMA4_ACCEL_SELFTEST_ENABLE_MSK, &__devFptr)); bma4_selftest_config(BMA4_ACCEL_SELFTEST_ENABLE_MSK, &__devFptr));
} }
uint8_t BMA423::getDirection() uint8_t BMA423::getDirection() {
{
Accel acc; Accel acc;
if (bma4_read_accel_xyz(&acc, &__devFptr) != BMA4_OK) { if (bma4_read_accel_xyz(&acc, &__devFptr) != BMA4_OK) {
return 0; return 0;
@ -150,8 +132,7 @@ uint8_t BMA423::getDirection()
} }
} }
float BMA423::readTemperature() float BMA423::readTemperature() {
{
int32_t data = 0; int32_t data = 0;
bma4_get_temperature(&data, BMA4_DEG, &__devFptr); bma4_get_temperature(&data, BMA4_DEG, &__devFptr);
float res = (float)data / (float)BMA4_SCALE_TEMP; float res = (float)data / (float)BMA4_SCALE_TEMP;
@ -164,9 +145,7 @@ float BMA423::readTemperature()
return res; return res;
} }
float BMA423::readTemperatureF() {
float BMA423::readTemperatureF()
{
float temp = readTemperature(); float temp = readTemperature();
if (temp != 0) { if (temp != 0) {
temp = temp * 1.8 + 32.0; temp = temp * 1.8 + 32.0;
@ -174,8 +153,7 @@ float BMA423::readTemperatureF()
return (temp); return (temp);
} }
bool BMA423::getAccel(Accel &acc) bool BMA423::getAccel(Accel &acc) {
{
memset(&acc, 0, sizeof(acc)); memset(&acc, 0, sizeof(acc));
if (bma4_read_accel_xyz(&acc, &__devFptr) != BMA4_OK) { if (bma4_read_accel_xyz(&acc, &__devFptr) != BMA4_OK) {
return false; return false;
@ -183,45 +161,36 @@ bool BMA423::getAccel(Accel &acc)
return true; return true;
} }
bool BMA423::getAccelEnable() bool BMA423::getAccelEnable() {
{
uint8_t en; uint8_t en;
bma4_get_accel_enable(&en, &__devFptr); bma4_get_accel_enable(&en, &__devFptr);
return (en & BMA4_ACCEL_ENABLE_POS) == BMA4_ACCEL_ENABLE_POS; return (en & BMA4_ACCEL_ENABLE_POS) == BMA4_ACCEL_ENABLE_POS;
} }
bool BMA423::disableAccel() bool BMA423::disableAccel() { return enableAccel(false); }
{
return enableAccel(false); bool BMA423::enableAccel(bool en) {
return (BMA4_OK ==
bma4_set_accel_enable(en ? BMA4_ENABLE : BMA4_DISABLE, &__devFptr));
} }
bool BMA423::enableAccel(bool en) bool BMA423::setAccelConfig(Acfg &cfg) {
{
return (BMA4_OK == bma4_set_accel_enable(en ? BMA4_ENABLE : BMA4_DISABLE, &__devFptr));
}
bool BMA423::setAccelConfig(Acfg &cfg)
{
return (BMA4_OK == bma4_set_accel_config(&cfg, &__devFptr)); return (BMA4_OK == bma4_set_accel_config(&cfg, &__devFptr));
} }
bool BMA423::getAccelConfig(Acfg &cfg) bool BMA423::getAccelConfig(Acfg &cfg) {
{
return (BMA4_OK == bma4_get_accel_config(&cfg, &__devFptr)); return (BMA4_OK == bma4_get_accel_config(&cfg, &__devFptr));
} }
bool BMA423::setRemapAxes(struct bma423_axes_remap *remap_data) bool BMA423::setRemapAxes(struct bma423_axes_remap *remap_data) {
{
return (BMA4_OK == bma423_set_remap_axes(remap_data, &__devFptr)); return (BMA4_OK == bma423_set_remap_axes(remap_data, &__devFptr));
} }
bool BMA423::resetStepCounter() bool BMA423::resetStepCounter() {
{ return BMA4_OK == bma423_reset_step_counter(&__devFptr);
return BMA4_OK == bma423_reset_step_counter(&__devFptr) ;
} }
uint32_t BMA423::getCounter() uint32_t BMA423::getCounter() {
{
uint32_t stepCount; uint32_t stepCount;
if (bma423_step_counter_output(&stepCount, &__devFptr) == BMA4_OK) { if (bma423_step_counter_output(&stepCount, &__devFptr) == BMA4_OK) {
return stepCount; return stepCount;
@ -229,91 +198,76 @@ uint32_t BMA423::getCounter()
return 0; return 0;
} }
bool BMA423::setINTPinConfig(struct bma4_int_pin_config config, uint8_t pinMap) bool BMA423::setINTPinConfig(struct bma4_int_pin_config config,
{ uint8_t pinMap) {
return BMA4_OK == bma4_set_int_pin_config(&config, pinMap, &__devFptr); return BMA4_OK == bma4_set_int_pin_config(&config, pinMap, &__devFptr);
} }
bool BMA423::getINT() bool BMA423::getINT() {
{
return bma423_read_int_status(&__IRQ_MASK, &__devFptr) == BMA4_OK; return bma423_read_int_status(&__IRQ_MASK, &__devFptr) == BMA4_OK;
} }
uint8_t BMA423::getIRQMASK() uint8_t BMA423::getIRQMASK() { return __IRQ_MASK; }
{
return __IRQ_MASK; bool BMA423::disableIRQ(uint16_t int_map) {
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, int_map, BMA4_DISABLE,
&__devFptr));
} }
bool BMA423::disableIRQ(uint16_t int_map) bool BMA423::enableIRQ(uint16_t int_map) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, int_map, BMA4_ENABLE,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, int_map, BMA4_DISABLE, &__devFptr)); &__devFptr));
} }
bool BMA423::enableIRQ(uint16_t int_map) bool BMA423::enableFeature(uint8_t feature, uint8_t enable) {
{
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, int_map, BMA4_ENABLE, &__devFptr));
}
bool BMA423::enableFeature(uint8_t feature, uint8_t enable)
{
if ((feature & BMA423_STEP_CNTR) == BMA423_STEP_CNTR) { if ((feature & BMA423_STEP_CNTR) == BMA423_STEP_CNTR) {
bma423_step_detector_enable(enable ? BMA4_ENABLE : BMA4_DISABLE, &__devFptr); bma423_step_detector_enable(enable ? BMA4_ENABLE : BMA4_DISABLE,
&__devFptr);
} }
return (BMA4_OK == bma423_feature_enable(feature, enable, &__devFptr)); return (BMA4_OK == bma423_feature_enable(feature, enable, &__devFptr));
} }
bool BMA423::isStepCounter() bool BMA423::isStepCounter() {
{
return (bool)(BMA423_STEP_CNTR_INT & __IRQ_MASK); return (bool)(BMA423_STEP_CNTR_INT & __IRQ_MASK);
} }
bool BMA423::isDoubleClick() bool BMA423::isDoubleClick() { return (bool)(BMA423_WAKEUP_INT & __IRQ_MASK); }
{
return (bool)(BMA423_WAKEUP_INT & __IRQ_MASK);
}
bool BMA423::isTilt() bool BMA423::isTilt() { return (bool)(BMA423_TILT_INT & __IRQ_MASK); }
{
return (bool)(BMA423_TILT_INT & __IRQ_MASK);
}
bool BMA423::isActivity() bool BMA423::isActivity() { return (bool)(BMA423_ACTIVITY_INT & __IRQ_MASK); }
{
return (bool)(BMA423_ACTIVITY_INT & __IRQ_MASK);
}
bool BMA423::isAnyNoMotion() bool BMA423::isAnyNoMotion() {
{
return (bool)(BMA423_ANY_NO_MOTION_INT & __IRQ_MASK); return (bool)(BMA423_ANY_NO_MOTION_INT & __IRQ_MASK);
} }
bool BMA423::enableStepCountInterrupt(bool en) bool BMA423::enableStepCountInterrupt(bool en) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_STEP_CNTR_INT, en, &__devFptr)); en, &__devFptr));
} }
bool BMA423::enableTiltInterrupt(bool en) bool BMA423::enableTiltInterrupt(bool en) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_TILT_INT, en,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_TILT_INT, en, &__devFptr)); &__devFptr));
} }
bool BMA423::enableWakeupInterrupt(bool en) bool BMA423::enableWakeupInterrupt(bool en) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_WAKEUP_INT, en,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_WAKEUP_INT, en, &__devFptr)); &__devFptr));
} }
bool BMA423::enableAnyNoMotionInterrupt(bool en) bool BMA423::enableAnyNoMotionInterrupt(bool en) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ANY_NO_MOTION_INT, en, &__devFptr)); BMA423_ANY_NO_MOTION_INT, en,
&__devFptr));
} }
bool BMA423::enableActivityInterrupt(bool en) bool BMA423::enableActivityInterrupt(bool en) {
{ return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ACTIVITY_INT,
return (BMA4_OK == bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ACTIVITY_INT, en, &__devFptr)); en, &__devFptr));
} }
const char *BMA423::getActivity() const char *BMA423::getActivity() {
{
uint8_t activity; uint8_t activity;
bma423_activity_output(&activity, &__devFptr); bma423_activity_output(&activity, &__devFptr);
if (activity & BMA423_USER_STATIONARY) { if (activity & BMA423_USER_STATIONARY) {

View File

@ -15,19 +15,19 @@ enum {
DIRECTION_RIGHT_EDGE = 3, DIRECTION_RIGHT_EDGE = 3,
DIRECTION_DISP_UP = 4, DIRECTION_DISP_UP = 4,
DIRECTION_DISP_DOWN = 5 DIRECTION_DISP_DOWN = 5
} ; };
typedef struct bma4_accel Accel; typedef struct bma4_accel Accel;
typedef struct bma4_accel_config Acfg; typedef struct bma4_accel_config Acfg;
class BMA423 class BMA423 {
{
public: public:
BMA423(); BMA423();
~BMA423(); ~BMA423();
bool begin(bma4_com_fptr_t readCallBlack, bma4_com_fptr_t writeCallBlack, bma4_delay_fptr_t delayCallBlack, bool begin(bma4_com_fptr_t readCallBlack, bma4_com_fptr_t writeCallBlack,
bma4_delay_fptr_t delayCallBlack,
uint8_t address = BMA4_I2C_ADDR_PRIMARY); uint8_t address = BMA4_I2C_ADDR_PRIMARY);
void softReset(); void softReset();
@ -65,11 +65,10 @@ public:
uint16_t getStatus(); uint16_t getStatus();
uint32_t getSensorTime(); uint32_t getSensorTime();
const char *getActivity(); const char *getActivity();
bool setRemapAxes(struct bma423_axes_remap *remap_data); bool setRemapAxes(struct bma423_axes_remap *remap_data);
bool enableFeature(uint8_t feature, uint8_t enable ); bool enableFeature(uint8_t feature, uint8_t enable);
bool enableStepCountInterrupt(bool en = true); bool enableStepCountInterrupt(bool en = true);
bool enableTiltInterrupt(bool en = true); bool enableTiltInterrupt(bool en = true);
bool enableWakeupInterrupt(bool en = true); bool enableWakeupInterrupt(bool en = true);

File diff suppressed because it is too large Load Diff

View File

@ -1,87 +1,87 @@
/* /*
* *
**************************************************************************** ****************************************************************************
* Copyright (C) 2015 - 2016 Bosch Sensortec GmbH * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
* *
* File : bma4.h * File : bma4.h
* *
* Date: 12 Oct 2017 * Date: 12 Oct 2017
* *
* Revision: 2.1.9 $ * Revision: 2.1.9 $
* *
* Usage: Sensor Driver for BMA4 family of sensors * Usage: Sensor Driver for BMA4 family of sensors
* *
**************************************************************************** ****************************************************************************
* *
* Disclaimer * Disclaimer
* *
* Common: * Common:
* Bosch Sensortec products are developed for the consumer goods industry. * Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid * They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the * product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a * express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining, * particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device * safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system * that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are * or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems. * not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and * The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use * his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser. * is the sole responsibility of the Purchaser.
* *
* The purchaser shall indemnify Bosch Sensortec from all third party * The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages, * claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of * arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by * the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in * Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims. * connection with such claims.
* *
* The purchaser must monitor the market for the purchased products, * The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec * particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents. * without delay of all security relevant incidents.
* *
* Engineering Samples are marked with an asterisk (*) or (e). * Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product * Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third * series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal * parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way * client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes * replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples. * no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify * By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering * Bosch Sensortec from all claims arising from the use of engineering
* samples. * samples.
* *
* Special: * Special:
* This software module (hereinafter called "Software") and any information * This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided * on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work. * free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following * The Software and Information is subject to the following
* terms and conditions: * terms and conditions:
* *
* The Software is specifically designed for the exclusive use for * The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience * Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the * and training. Do not use this Software if you do not have the
* proper experience or training. * proper experience or training.
* *
* This Software package is provided `` as is `` and without any expressed * This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties * or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose. * of merchantability and fitness for a particular purpose.
* *
* Bosch Sensortec and their representatives and agents deny any liability * Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment * for the functional impairment
* of this Software in terms of fitness, performance and safety. * of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable * Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as * for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law. * otherwise stipulated in mandatory applicable law.
* *
* The Information provided is believed to be accurate and reliable. * The Information provided is believed to be accurate and reliable.
* Bosch Sensortec assumes no responsibility for the consequences of use * Bosch Sensortec assumes no responsibility for the consequences of use
* of such Information nor for any infringement of patents or * of such Information nor for any infringement of patents or
* other rights of third parties which may result from its use. * other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or * No license is granted by implication or otherwise under any patent or
* patent rights of Bosch. Specifications mentioned in the Information are * patent rights of Bosch. Specifications mentioned in the Information are
* subject to change without notice. * subject to change without notice.
**************************************************************************/ **************************************************************************/
/*! \file bma4.h /*! \file bma4.h
\brief Sensor Driver for BMA4 family of sensors */ \brief Sensor Driver for BMA4 family of sensors */
#ifndef BMA4_H__ #ifndef BMA4_H__
@ -157,7 +157,8 @@ uint16_t bma4_write_config_file(struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma4_write_regs(uint8_t addr, uint8_t *data, uint8_t len, struct bma4_dev *dev); uint16_t bma4_write_regs(uint8_t addr, uint8_t *data, uint8_t len,
struct bma4_dev *dev);
/*! /*!
* @brief This API checks whether the read operation requested is for * @brief This API checks whether the read operation requested is for
@ -172,7 +173,8 @@ uint16_t bma4_write_regs(uint8_t addr, uint8_t *data, uint8_t len, struct bma4_d
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma4_read_regs(uint8_t addr, uint8_t *data, uint8_t len, struct bma4_dev *dev); uint16_t bma4_read_regs(uint8_t addr, uint8_t *data, uint8_t len,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the error status from the sensor. * @brief This API reads the error status from the sensor.
@ -211,7 +213,8 @@ uint16_t bma4_read_regs(uint8_t addr, uint8_t *data, uint8_t len, struct bma4_de
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma4_get_error_status(struct bma4_err_reg *err_reg, struct bma4_dev *dev); uint16_t bma4_get_error_status(struct bma4_err_reg *err_reg,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the sensor status from the dev sensor. * @brief This API reads the sensor status from the dev sensor.
@ -291,7 +294,8 @@ uint16_t bma4_get_sensor_time(uint32_t *sensor_time, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_temperature(int32_t *temp, uint8_t temp_unit, struct bma4_dev *dev); uint16_t bma4_get_temperature(int32_t *temp, uint8_t temp_unit,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the Output data rate, Bandwidth, perf_mode * @brief This API reads the Output data rate, Bandwidth, perf_mode
@ -342,7 +346,8 @@ uint16_t bma4_get_temperature(int32_t *temp, uint8_t temp_unit, struct bma4_dev
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_accel_config(struct bma4_accel_config *accel, struct bma4_dev *dev); uint16_t bma4_get_accel_config(struct bma4_accel_config *accel,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the output_data_rate, bandwidth, perf_mode * @brief This API sets the output_data_rate, bandwidth, perf_mode
@ -393,7 +398,8 @@ uint16_t bma4_get_accel_config(struct bma4_accel_config *accel, struct bma4_dev
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_set_accel_config(const struct bma4_accel_config *accel, struct bma4_dev *dev); uint16_t bma4_set_accel_config(const struct bma4_accel_config *accel,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the advance power save mode in the sensor. * @brief This API sets the advance power save mode in the sensor.
@ -429,7 +435,8 @@ uint16_t bma4_set_advance_power_save(uint8_t adv_pwr_save,
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_advance_power_save(uint8_t *adv_pwr_save, struct bma4_dev *dev); uint16_t bma4_get_advance_power_save(uint8_t *adv_pwr_save,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the FIFO self wake up functionality in the sensor. * @brief This API sets the FIFO self wake up functionality in the sensor.
@ -446,7 +453,8 @@ uint16_t bma4_get_advance_power_save(uint8_t *adv_pwr_save, struct bma4_dev *dev
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_set_fifo_self_wakeup(uint8_t fifo_self_wakeup, struct bma4_dev *dev); uint16_t bma4_set_fifo_self_wakeup(uint8_t fifo_self_wakeup,
struct bma4_dev *dev);
/*! /*!
* @brief This API gets the status of FIFO self wake up functionality from * @brief This API gets the status of FIFO self wake up functionality from
@ -464,7 +472,8 @@ uint16_t bma4_set_fifo_self_wakeup(uint8_t fifo_self_wakeup, struct bma4_dev *de
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_fifo_self_wakeup(uint8_t *fifo_self_wake_up, struct bma4_dev *dev); uint16_t bma4_get_fifo_self_wakeup(uint8_t *fifo_self_wake_up,
struct bma4_dev *dev);
/*! /*!
* @brief This API enables or disables the Accel in the sensor. * @brief This API enables or disables the Accel in the sensor.
@ -562,7 +571,7 @@ uint16_t bma4_get_spi_interface(uint8_t *spi, struct bma4_dev *dev);
*/ */
uint16_t bma4_set_spi_interface(uint8_t spi, struct bma4_dev *dev); uint16_t bma4_set_spi_interface(uint8_t spi, struct bma4_dev *dev);
/*! /*!
* @brief This API writes the available sensor specific commands * @brief This API writes the available sensor specific commands
* to the sensor. * to the sensor.
* *
@ -851,7 +860,8 @@ uint16_t bma4_set_fifo_wm(uint16_t fifo_wm, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_accel_fifo_filter_data(uint8_t *accel_fifo_filter, struct bma4_dev *dev); uint16_t bma4_get_accel_fifo_filter_data(uint8_t *accel_fifo_filter,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the condition of Accel FIFO data either to * @brief This API sets the condition of Accel FIFO data either to
@ -870,7 +880,8 @@ uint16_t bma4_get_accel_fifo_filter_data(uint8_t *accel_fifo_filter, struct bma4
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_set_accel_fifo_filter_data(uint8_t accel_fifo_filter, struct bma4_dev *dev); uint16_t bma4_set_accel_fifo_filter_data(uint8_t accel_fifo_filter,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the down sampling rates which is configured * @brief This API reads the down sampling rates which is configured
@ -939,7 +950,8 @@ uint16_t bma4_get_fifo_length(uint16_t *fifo_length, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_second_if_mag_compensate_xyz(struct bma4_mag_fifo_data mag_fifo_data, uint16_t
bma4_second_if_mag_compensate_xyz(struct bma4_mag_fifo_data mag_fifo_data,
uint8_t mag_second_if, uint8_t mag_second_if,
struct bma4_mag *compensated_mag_data); struct bma4_mag *compensated_mag_data);
@ -963,7 +975,8 @@ uint16_t bma4_second_if_mag_compensate_xyz(struct bma4_mag_fifo_data mag_fifo_da
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_read_mag_xyz(struct bma4_mag *mag, uint8_t sensor_select, struct bma4_dev *dev); uint16_t bma4_read_mag_xyz(struct bma4_mag *mag, uint8_t sensor_select,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the auxiliary I2C interface configuration which * @brief This API reads the auxiliary I2C interface configuration which
@ -1056,7 +1069,8 @@ uint16_t bma4_get_mag_data_rdy(uint8_t *data_rdy, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_asic_status(struct bma4_asic_status *asic_status, struct bma4_dev *dev); uint16_t bma4_get_asic_status(struct bma4_asic_status *asic_status,
struct bma4_dev *dev);
/*! /*!
* @brief This API enables the offset compensation for filtered and * @brief This API enables the offset compensation for filtered and
@ -1122,7 +1136,8 @@ uint16_t bma4_get_offset_comp(uint8_t *offset_en, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_extract_accel(struct bma4_accel *accel_data, uint16_t *accel_length, const struct bma4_dev *dev); uint16_t bma4_extract_accel(struct bma4_accel *accel_data,
uint16_t *accel_length, const struct bma4_dev *dev);
/*! /*!
* @brief This API parses and extracts the magnetometer frames from * @brief This API parses and extracts the magnetometer frames from
@ -1148,7 +1163,8 @@ uint16_t bma4_extract_accel(struct bma4_accel *accel_data, uint16_t *accel_lengt
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_extract_mag(struct bma4_mag *mag_data, uint16_t *mag_length, const struct bma4_dev *dev); uint16_t bma4_extract_mag(struct bma4_mag *mag_data, uint16_t *mag_length,
const struct bma4_dev *dev);
/*! /*!
* @brief This API performs Fast Offset Compensation for Accel. * @brief This API performs Fast Offset Compensation for Accel.
@ -1170,7 +1186,8 @@ uint16_t bma4_extract_mag(struct bma4_mag *mag_data, uint16_t *mag_length, const
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_perform_accel_foc(const int32_t accel_g_value[3], struct bma4_dev *dev); uint16_t bma4_perform_accel_foc(const int32_t accel_g_value[3],
struct bma4_dev *dev);
/*! /*!
* @brief This API checks whether the self test functionality of the sensor * @brief This API checks whether the self test functionality of the sensor
* is working or not * is working or not
@ -1230,7 +1247,8 @@ uint16_t bma4_selftest_config(uint8_t sign, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable, struct bma4_dev *dev); uint16_t bma4_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the interrupt mode in the sensor. * @brief This API sets the interrupt mode in the sensor.
@ -1305,7 +1323,8 @@ uint16_t bma4_get_interrupt_mode(uint8_t *mode, struct bma4_dev *dev);
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_set_aux_mag_config(const struct bma4_aux_mag_config *aux_mag, struct bma4_dev *dev); uint16_t bma4_set_aux_mag_config(const struct bma4_aux_mag_config *aux_mag,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the auxiliary Mag(BMM150 or AKM9916) output data * @brief This API reads the auxiliary Mag(BMM150 or AKM9916) output data
@ -1343,7 +1362,8 @@ uint16_t bma4_set_aux_mag_config(const struct bma4_aux_mag_config *aux_mag, stru
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_aux_mag_config(struct bma4_aux_mag_config *aux_mag, struct bma4_dev *dev); uint16_t bma4_get_aux_mag_config(struct bma4_aux_mag_config *aux_mag,
struct bma4_dev *dev);
/*! @brief This API sets the FIFO configuration in the sensor. /*! @brief This API sets the FIFO configuration in the sensor.
* *
@ -1372,7 +1392,8 @@ uint16_t bma4_get_aux_mag_config(struct bma4_aux_mag_config *aux_mag, struct bma
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_set_fifo_config(uint8_t config, uint8_t enable, struct bma4_dev *dev); uint16_t bma4_set_fifo_config(uint8_t config, uint8_t enable,
struct bma4_dev *dev);
/*! @brief This API reads the FIFO configuration from the sensor. /*! @brief This API reads the FIFO configuration from the sensor.
* *
@ -1441,8 +1462,9 @@ uint16_t bma4_get_fifo_config(uint8_t *fifo_config, struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma4_set_int_pin_config(const struct bma4_int_pin_config *int_pin_config, uint8_t int_line, uint16_t
struct bma4_dev *dev); bma4_set_int_pin_config(const struct bma4_int_pin_config *int_pin_config,
uint8_t int_line, struct bma4_dev *dev);
/*! @brief This API reads the electrical behavior of interrupt pin1 or pin2 /*! @brief This API reads the electrical behavior of interrupt pin1 or pin2
* from the sensor. * from the sensor.
@ -1483,10 +1505,12 @@ uint16_t bma4_set_int_pin_config(const struct bma4_int_pin_config *int_pin_confi
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_get_int_pin_config(struct bma4_int_pin_config *int_pin_config, uint8_t int_line, struct bma4_dev *dev); uint16_t bma4_get_int_pin_config(struct bma4_int_pin_config *int_pin_config,
uint8_t int_line, struct bma4_dev *dev);
/*! /*!
* @brief This API reads the Feature and Hardware interrupt status from the sensor. * @brief This API reads the Feature and Hardware interrupt status from the
*sensor.
* *
* @param[out] int_status : Variable used to get the interrupt status. * @param[out] int_status : Variable used to get the interrupt status.
* @param[in] dev : Structure instance of bma4_dev. * @param[in] dev : Structure instance of bma4_dev.
@ -1544,14 +1568,16 @@ uint16_t bma4_aux_interface_init(struct bma4_dev *dev);
* @param[in] len : User specified data length * @param[in] len : User specified data length
* @param[out] aux_data : Pointer variable to store data read * @param[out] aux_data : Pointer variable to store data read
* @param[in] aux_reg_addr : Variable to pass address from where * @param[in] aux_reg_addr : Variable to pass address from where
* data is to be read * data is to be
*read
* *
* @return Result of API execution status * @return Result of API execution status
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_aux_read(uint8_t aux_reg_addr, uint8_t *aux_data, uint16_t len, struct bma4_dev *dev); uint16_t bma4_aux_read(uint8_t aux_reg_addr, uint8_t *aux_data, uint16_t len,
struct bma4_dev *dev);
/*! /*!
* @brief This API writes the data into the auxiliary sensor * @brief This API writes the data into the auxiliary sensor
@ -1560,15 +1586,16 @@ uint16_t bma4_aux_read(uint8_t aux_reg_addr, uint8_t *aux_data, uint16_t len, st
* @param[in] len : User specified data length * @param[in] len : User specified data length
* @param[out] aux_data : Pointer variable to store data read * @param[out] aux_data : Pointer variable to store data read
* @param[in] aux_reg_addr : Variable to pass address from where * @param[in] aux_reg_addr : Variable to pass address from where
* data is to be written * data is to be
*written
* *
* @return Result of API execution status * @return Result of API execution status
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
* *
*/ */
uint16_t bma4_aux_write(uint8_t aux_reg_addr, uint8_t *aux_data, uint16_t len, struct bma4_dev *dev); uint16_t bma4_aux_write(uint8_t aux_reg_addr, uint8_t *aux_data, uint16_t len,
struct bma4_dev *dev);
#endif #endif
/* End of __BMA4_H__ */ /* End of __BMA4_H__ */

View File

@ -1,87 +1,87 @@
/**\mainpage /**\mainpage
* *
**************************************************************************** ****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
* *
* File : bma423.c * File : bma423.c
* *
* Date: 12 Oct 2017 * Date: 12 Oct 2017
* *
* Revision : 1.1.4 $ * Revision : 1.1.4 $
* *
* Usage: Sensor Driver for BMA423 sensor * Usage: Sensor Driver for BMA423 sensor
* *
**************************************************************************** ****************************************************************************
* *
* \section Disclaimer * \section Disclaimer
* *
* Common: * Common:
* Bosch Sensortec products are developed for the consumer goods industry. * Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid * They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the * product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a * express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining, * particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device * safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system * that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are * or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems. * not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and * The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use * his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser. * is the sole responsibility of the Purchaser.
* *
* The purchaser shall indemnify Bosch Sensortec from all third party * The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages, * claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of * arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by * the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in * Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims. * connection with such claims.
* *
* The purchaser must monitor the market for the purchased products, * The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec * particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents. * without delay of all security relevant incidents.
* *
* Engineering Samples are marked with an asterisk (*) or (e). * Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product * Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third * series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal * parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way * client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes * replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples. * no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify * By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering * Bosch Sensortec from all claims arising from the use of engineering
* samples. * samples.
* *
* Special: * Special:
* This software module (hereinafter called "Software") and any information * This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided * on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work. * free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following * The Software and Information is subject to the following
* terms and conditions: * terms and conditions:
* *
* The Software is specifically designed for the exclusive use for * The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience * Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the * and training. Do not use this Software if you do not have the
* proper experience or training. * proper experience or training.
* *
* This Software package is provided `` as is `` and without any expressed * This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties * or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose. * of merchantability and fitness for a particular purpose.
* *
* Bosch Sensortec and their representatives and agents deny any liability * Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment * for the functional impairment
* of this Software in terms of fitness, performance and safety. * of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable * Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as * for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law. * otherwise stipulated in mandatory applicable law.
* *
* The Information provided is believed to be accurate and reliable. * The Information provided is believed to be accurate and reliable.
* Bosch Sensortec assumes no responsibility for the consequences of use * Bosch Sensortec assumes no responsibility for the consequences of use
* of such Information nor for any infringement of patents or * of such Information nor for any infringement of patents or
* other rights of third parties which may result from its use. * other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or * No license is granted by implication or otherwise under any patent or
* patent rights of Bosch. Specifications mentioned in the Information are * patent rights of Bosch. Specifications mentioned in the Information are
* subject to change without notice. * subject to change without notice.
**************************************************************************/ **************************************************************************/
/*! \file bma423.c /*! \file bma423.c
\brief Sensor Driver for BMA423 sensor */ \brief Sensor Driver for BMA423 sensor */
@ -600,8 +600,7 @@ const uint8_t bma423_config_file[] = {
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00,
0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00};
};
/***************************************************************************/ /***************************************************************************/
/*! Static Function Declarations /*! Static Function Declarations
@ -638,7 +637,8 @@ static void update_len(uint8_t *len, uint8_t feature, uint8_t enable);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any positive value mentioned in ERROR CODES -> Fail * @retval Any positive value mentioned in ERROR CODES -> Fail
*/ */
static uint16_t feature_enable(uint8_t feature, uint8_t len, uint8_t *feature_config, struct bma4_dev *dev); static uint16_t feature_enable(uint8_t feature, uint8_t len,
uint8_t *feature_config, struct bma4_dev *dev);
/*! /*!
* @brief This API disables the features of sensor. * @brief This API disables the features of sensor.
@ -654,7 +654,8 @@ static uint16_t feature_enable(uint8_t feature, uint8_t len, uint8_t *feature_co
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any positive value mentioned in ERROR CODES -> Fail * @retval Any positive value mentioned in ERROR CODES -> Fail
*/ */
static uint16_t feature_disable(uint8_t feature, uint8_t len, uint8_t *feature_config, struct bma4_dev *dev); static uint16_t feature_disable(uint8_t feature, uint8_t len,
uint8_t *feature_config, struct bma4_dev *dev);
/*! /*!
* @brief This API update the settings of step counter into write array. * @brief This API update the settings of step counter into write array.
@ -666,7 +667,8 @@ static uint16_t feature_disable(uint8_t feature, uint8_t len, uint8_t *feature_c
* *
* @return none * @return none
*/ */
static void update_stepcounter_parameter(const struct bma423_stepcounter_settings *setting, static void
update_stepcounter_parameter(const struct bma423_stepcounter_settings *setting,
uint8_t index, uint8_t *feature_config); uint8_t index, uint8_t *feature_config);
/*! /*!
* @brief This API copy the settings of step counter into the * @brief This API copy the settings of step counter into the
@ -678,7 +680,9 @@ static void update_stepcounter_parameter(const struct bma423_stepcounter_setting
* *
* @return none * @return none
*/ */
static void extract_stepcounter_parameter(struct bma423_stepcounter_settings *setting, const uint16_t *data_p); static void
extract_stepcounter_parameter(struct bma423_stepcounter_settings *setting,
const uint16_t *data_p);
/***************************************************************************/ /***************************************************************************/
/**\name Function definitions /**\name Function definitions
@ -690,8 +694,7 @@ static void extract_stepcounter_parameter(struct bma423_stepcounter_settings *se
* This API reads the chip-id of the sensor and sets the resolution. * This API reads the chip-id of the sensor and sets the resolution.
*/ */
#include <stdio.h> #include <stdio.h>
uint16_t bma423_init(struct bma4_dev *dev) uint16_t bma423_init(struct bma4_dev *dev) {
{
uint16_t rslt; uint16_t rslt;
rslt = bma4_init(dev); rslt = bma4_init(dev);
@ -714,8 +717,7 @@ uint16_t bma423_init(struct bma4_dev *dev)
* @brief This API is used to upload the config file to enable * @brief This API is used to upload the config file to enable
* the features of the sensor. * the features of the sensor.
*/ */
uint16_t bma423_write_config_file(struct bma4_dev *dev) uint16_t bma423_write_config_file(struct bma4_dev *dev) {
{
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
@ -744,8 +746,7 @@ uint16_t bma423_write_config_file(struct bma4_dev *dev)
/*! /*!
* @brief This API is used to get the configuration id of the sensor. * @brief This API is used to get the configuration id of the sensor.
*/ */
uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev) uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev) {
{
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_CONFIG_ID_OFFSET; uint8_t index = BMA423_CONFIG_ID_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
@ -754,7 +755,8 @@ uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev)
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
config_id_lsb = (uint16_t)feature_config[index]; config_id_lsb = (uint16_t)feature_config[index];
config_id_msb = ((uint16_t)feature_config[index + 1]) << 8; config_id_msb = ((uint16_t)feature_config[index + 1]) << 8;
@ -774,8 +776,8 @@ uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev)
* @brief This API sets/unsets the user provided interrupt to either * @brief This API sets/unsets the user provided interrupt to either
* interrupt pin1 or pin2 in the sensor. * interrupt pin1 or pin2 in the sensor.
*/ */
uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable, struct bma4_dev *dev) uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map,
{ uint8_t enable, struct bma4_dev *dev) {
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
@ -799,8 +801,7 @@ uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable
/*! /*!
* @brief This API reads the bma423 interrupt status from the sensor. * @brief This API reads the bma423 interrupt status from the sensor.
*/ */
uint16_t bma423_read_int_status(uint16_t *int_status, struct bma4_dev *dev) uint16_t bma423_read_int_status(uint16_t *int_status, struct bma4_dev *dev) {
{
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
@ -820,8 +821,8 @@ uint16_t bma423_read_int_status(uint16_t *int_status, struct bma4_dev *dev)
/*! /*!
* @brief This API enables/disables the features of the sensor. * @brief This API enables/disables the features of the sensor.
*/ */
uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable, struct bma4_dev *dev) uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
uint8_t len; uint8_t len;
@ -853,8 +854,8 @@ uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable, struct bma4_dev
/*! /*!
* @brief This API performs x, y and z axis remapping in the sensor. * @brief This API performs x, y and z axis remapping in the sensor.
*/ */
uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struct bma4_dev *dev) uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_AXES_REMAP_OFFSET; uint8_t index = BMA423_AXES_REMAP_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
@ -866,15 +867,18 @@ uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struc
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
x_axis = remap_data->x_axis & BMA423_X_AXIS_MASK; x_axis = remap_data->x_axis & BMA423_X_AXIS_MASK;
x_axis_sign = (remap_data->x_axis_sign << 2) & BMA423_X_AXIS_SIGN_MASK; x_axis_sign = (remap_data->x_axis_sign << 2) & BMA423_X_AXIS_SIGN_MASK;
y_axis = (remap_data->y_axis << 3) & BMA423_Y_AXIS_MASK; y_axis = (remap_data->y_axis << 3) & BMA423_Y_AXIS_MASK;
y_axis_sign = (remap_data->y_axis_sign << 5) & BMA423_Y_AXIS_SIGN_MASK; y_axis_sign = (remap_data->y_axis_sign << 5) & BMA423_Y_AXIS_SIGN_MASK;
z_axis = (remap_data->z_axis << 6) & BMA423_Z_AXIS_MASK; z_axis = (remap_data->z_axis << 6) & BMA423_Z_AXIS_MASK;
feature_config[index] = x_axis | x_axis_sign | y_axis | y_axis_sign | z_axis; feature_config[index] =
feature_config[index + 1] = remap_data->z_axis_sign & BMA423_Z_AXIS_SIGN_MASK; x_axis | x_axis_sign | y_axis | y_axis_sign | z_axis;
feature_config[index + 1] =
remap_data->z_axis_sign & BMA423_Z_AXIS_SIGN_MASK;
rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
} }
@ -891,22 +895,26 @@ uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struc
/*! /*!
* @brief This API reads the x, y and z axis remap data from the sensor. * @brief This API reads the x, y and z axis remap data from the sensor.
*/ */
uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data, struct bma4_dev *dev) uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_AXES_REMAP_OFFSET; uint8_t index = BMA423_AXES_REMAP_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
remap_data->x_axis = feature_config[index] & BMA423_X_AXIS_MASK; remap_data->x_axis = feature_config[index] & BMA423_X_AXIS_MASK;
remap_data->x_axis_sign = (feature_config[index] & BMA423_X_AXIS_SIGN_MASK) >> 2; remap_data->x_axis_sign =
(feature_config[index] & BMA423_X_AXIS_SIGN_MASK) >> 2;
remap_data->y_axis = (feature_config[index] & BMA423_Y_AXIS_MASK) >> 3; remap_data->y_axis = (feature_config[index] & BMA423_Y_AXIS_MASK) >> 3;
remap_data->y_axis_sign = (feature_config[index] & BMA423_Y_AXIS_SIGN_MASK) >> 5; remap_data->y_axis_sign =
(feature_config[index] & BMA423_Y_AXIS_SIGN_MASK) >> 5;
remap_data->z_axis = (feature_config[index] & BMA423_Z_AXIS_MASK) >> 6; remap_data->z_axis = (feature_config[index] & BMA423_Z_AXIS_MASK) >> 6;
remap_data->z_axis_sign = (feature_config[index + 1] & BMA423_Z_AXIS_SIGN_MASK); remap_data->z_axis_sign =
(feature_config[index + 1] & BMA423_Z_AXIS_SIGN_MASK);
} }
} else { } else {
rslt = BMA4_E_INVALID_SENSOR; rslt = BMA4_E_INVALID_SENSOR;
@ -922,8 +930,7 @@ uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data, struct bma4
* @brief This API enables the any motion feature according to the axis * @brief This API enables the any motion feature according to the axis
* set by the user in the sensor. * set by the user in the sensor.
*/ */
uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev) uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev) {
{
uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0}; uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0};
/* Anymotion axis enable bit pos. is 3 byte ahead of the /* Anymotion axis enable bit pos. is 3 byte ahead of the
anymotion base address(0x00) */ anymotion base address(0x00) */
@ -935,8 +942,8 @@ uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev)
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_ANYMOTION_EN_LEN + 2, dev); BMA423_ANYMOTION_EN_LEN + 2, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
feature_config[index] = BMA4_SET_BITSLICE(feature_config[index], feature_config[index] = BMA4_SET_BITSLICE(
BMA423_ANY_NO_MOTION_AXIS_EN, axis); feature_config[index], BMA423_ANY_NO_MOTION_AXIS_EN, axis);
rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_ANYMOTION_EN_LEN + 2, dev); BMA423_ANYMOTION_EN_LEN + 2, dev);
} }
@ -953,8 +960,9 @@ uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev)
/*! @brief This API sets the configuration of Any motion feature in /*! @brief This API sets the configuration of Any motion feature in
* the sensor. * the sensor.
*/ */
uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_motion, struct bma4_dev *dev) uint16_t
{ bma423_set_any_motion_config(const struct bma423_anymotion_config *any_motion,
struct bma4_dev *dev) {
uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0}; uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0};
uint8_t index = BMA423_ANY_NO_MOTION_OFFSET; uint8_t index = BMA423_ANY_NO_MOTION_OFFSET;
uint16_t duration_lsb = 0; uint16_t duration_lsb = 0;
@ -971,15 +979,15 @@ uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_
feature_config[index++] = BMA4_GET_LSB(any_motion->threshold); feature_config[index++] = BMA4_GET_LSB(any_motion->threshold);
feature_config[index] = BMA4_GET_MSB(any_motion->threshold); feature_config[index] = BMA4_GET_MSB(any_motion->threshold);
/* Assign no motion selection value in feature config array*/ /* Assign no motion selection value in feature config array*/
feature_config[index++] |= (uint8_t) feature_config[index++] |=
(any_motion->nomotion_sel << BMA423_ANY_NO_MOTION_SEL_POS); (uint8_t)(any_motion->nomotion_sel << BMA423_ANY_NO_MOTION_SEL_POS);
/* Extract duration */ /* Extract duration */
duration_lsb = feature_config[index]; duration_lsb = feature_config[index];
duration_msb = feature_config[index + 1] << 8; duration_msb = feature_config[index + 1] << 8;
duration = duration_lsb | duration_msb; duration = duration_lsb | duration_msb;
duration = BMA4_SET_BITS_POS_0(duration, duration = BMA4_SET_BITS_POS_0(duration, BMA423_ANY_NO_MOTION_DUR,
BMA423_ANY_NO_MOTION_DUR, any_motion->duration); any_motion->duration);
/* Assign duration value in feature config array*/ /* Assign duration value in feature config array*/
feature_config[index++] = BMA4_GET_LSB(duration); feature_config[index++] = BMA4_GET_LSB(duration);
feature_config[index] = BMA4_GET_MSB(duration); feature_config[index] = BMA4_GET_MSB(duration);
@ -1001,8 +1009,9 @@ uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_
/*! @brief This API gets the configuration of any motion feature from /*! @brief This API gets the configuration of any motion feature from
* the sensor. * the sensor.
*/ */
uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion, struct bma4_dev *dev) uint16_t
{ bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion,
struct bma4_dev *dev) {
uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0}; uint8_t feature_config[BMA423_ANYMOTION_EN_LEN + 2] = {0};
uint8_t anymotion = 0; uint8_t anymotion = 0;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
@ -1017,10 +1026,10 @@ uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion
any_motion->threshold = (*data_p) & BMA423_ANY_NO_MOTION_THRES_MSK; any_motion->threshold = (*data_p) & BMA423_ANY_NO_MOTION_THRES_MSK;
/* Extract threshold & nomotion selection /* Extract threshold & nomotion selection
* data */ * data */
anymotion = ((uint8_t)(*(data_p++) >> 8)) & BMA423_ANY_NO_MOTION_SEL_MSK; anymotion =
((uint8_t)(*(data_p++) >> 8)) & BMA423_ANY_NO_MOTION_SEL_MSK;
/* Extract no motion field */ /* Extract no motion field */
any_motion->nomotion_sel = anymotion >> any_motion->nomotion_sel = anymotion >> BMA423_ANY_NO_MOTION_SEL_POS;
BMA423_ANY_NO_MOTION_SEL_POS;
/* Extract duration value */ /* Extract duration value */
any_motion->duration = (*(data_p)) & BMA423_ANY_NO_MOTION_DUR_MSK; any_motion->duration = (*(data_p)) & BMA423_ANY_NO_MOTION_DUR_MSK;
} }
@ -1038,8 +1047,7 @@ uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion
* @brief This API enables or disables the step detector feature in the * @brief This API enables or disables the step detector feature in the
* sensor. * sensor.
*/ */
uint16_t bma423_step_detector_enable(uint8_t enable, struct bma4_dev *dev) uint16_t bma423_step_detector_enable(uint8_t enable, struct bma4_dev *dev) {
{
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
/* Step detector enable bit pos. is 1 byte ahead of the base address */ /* Step detector enable bit pos. is 1 byte ahead of the base address */
@ -1050,8 +1058,8 @@ uint16_t bma423_step_detector_enable(uint8_t enable, struct bma4_dev *dev)
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
feature_config[index] = BMA4_SET_BITSLICE(feature_config[index], feature_config[index] = BMA4_SET_BITSLICE(
BMA423_STEP_DETECTOR_EN, enable); feature_config[index], BMA423_STEP_DETECTOR_EN, enable);
rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
} }
@ -1069,8 +1077,8 @@ uint16_t bma423_step_detector_enable(uint8_t enable, struct bma4_dev *dev)
* @brief This API sets the watermark level for step counter * @brief This API sets the watermark level for step counter
* interrupt in the sensor. * interrupt in the sensor.
*/ */
uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm, struct bma4_dev *dev) uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_STEP_CNTR_OFFSET; uint8_t index = BMA423_STEP_CNTR_OFFSET;
uint16_t wm_lsb = 0; uint16_t wm_lsb = 0;
@ -1112,8 +1120,8 @@ uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm, struct bma4
* @brief This API gets the water mark level set for step counter interrupt * @brief This API gets the water mark level set for step counter interrupt
* in the sensor * in the sensor
*/ */
uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm, struct bma4_dev *dev) uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_STEP_CNTR_OFFSET; uint8_t index = BMA423_STEP_CNTR_OFFSET;
uint16_t wm_lsb = 0; uint16_t wm_lsb = 0;
@ -1144,8 +1152,7 @@ uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm, struct bma
/*! /*!
* @brief This API resets the counted steps of step counter. * @brief This API resets the counted steps of step counter.
*/ */
uint16_t bma423_reset_step_counter(struct bma4_dev *dev) uint16_t bma423_reset_step_counter(struct bma4_dev *dev) {
{
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
/* Reset bit is 1 byte ahead of base address */ /* Reset bit is 1 byte ahead of base address */
uint8_t index = BMA423_STEP_CNTR_OFFSET + 1; uint8_t index = BMA423_STEP_CNTR_OFFSET + 1;
@ -1157,8 +1164,8 @@ uint16_t bma423_reset_step_counter(struct bma4_dev *dev)
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
feature_config[index] = BMA4_SET_BITSLICE(feature_config[index], feature_config[index] =
BMA423_STEP_CNTR_RST, 1); BMA4_SET_BITSLICE(feature_config[index], BMA423_STEP_CNTR_RST, 1);
rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
} }
@ -1175,8 +1182,8 @@ uint16_t bma423_reset_step_counter(struct bma4_dev *dev)
* @brief This API gets the number of counted steps of the step counter * @brief This API gets the number of counted steps of the step counter
* feature from the sensor. * feature from the sensor.
*/ */
uint16_t bma423_step_counter_output(uint32_t *step_count, struct bma4_dev *dev) uint16_t bma423_step_counter_output(uint32_t *step_count,
{ struct bma4_dev *dev) {
uint8_t data[BMA423_STEP_CNTR_DATA_SIZE] = {0}; uint8_t data[BMA423_STEP_CNTR_DATA_SIZE] = {0};
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
uint32_t step_count_0 = 0; uint32_t step_count_0 = 0;
@ -1211,8 +1218,7 @@ uint16_t bma423_step_counter_output(uint32_t *step_count, struct bma4_dev *dev)
/*! /*!
* @brief This API gets the output for activity feature. * @brief This API gets the output for activity feature.
*/ */
uint16_t bma423_activity_output(uint8_t *activity, struct bma4_dev *dev) uint16_t bma423_activity_output(uint8_t *activity, struct bma4_dev *dev) {
{
uint8_t data = 0; uint8_t data = 0;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
@ -1235,8 +1241,7 @@ uint16_t bma423_activity_output(uint8_t *activity, struct bma4_dev *dev)
/*! /*!
* @brief This API select the platform configuration wrist(Default) or phone. * @brief This API select the platform configuration wrist(Default) or phone.
*/ */
uint16_t bma423_select_platform(uint8_t platform, struct bma4_dev *dev) uint16_t bma423_select_platform(uint8_t platform, struct bma4_dev *dev) {
{
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
struct bma423_stepcounter_settings sc_settings = {0}; struct bma423_stepcounter_settings sc_settings = {0};
@ -1322,19 +1327,21 @@ uint16_t bma423_select_platform(uint8_t platform, struct bma4_dev *dev)
* @brief This API gets the parameter1 to parameter7 settings of the * @brief This API gets the parameter1 to parameter7 settings of the
* step counter feature. * step counter feature.
*/ */
uint16_t bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *setting, struct bma4_dev *dev) uint16_t
{ bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *setting,
struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint16_t *data_p = (uint16_t *)feature_config; uint16_t *data_p = (uint16_t *)feature_config;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
/* To convert 8bit to 16 bit address */ /* To convert 8bit to 16 bit address */
data_p = data_p + BMA423_STEP_CNTR_PARAM_OFFSET/2; data_p = data_p + BMA423_STEP_CNTR_PARAM_OFFSET / 2;
extract_stepcounter_parameter(setting, data_p); extract_stepcounter_parameter(setting, data_p);
} }
} else { } else {
@ -1351,15 +1358,16 @@ uint16_t bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *se
* @brief This API sets the parameter1 to parameter7 settings of the * @brief This API sets the parameter1 to parameter7 settings of the
* step counter feature in the sensor. * step counter feature in the sensor.
*/ */
uint16_t bma423_stepcounter_set_parameter(const struct bma423_stepcounter_settings *setting, struct bma4_dev *dev) uint16_t bma423_stepcounter_set_parameter(
{ const struct bma423_stepcounter_settings *setting, struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_STEP_CNTR_PARAM_OFFSET; uint8_t index = BMA423_STEP_CNTR_PARAM_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
update_stepcounter_parameter(setting, index, feature_config); update_stepcounter_parameter(setting, index, feature_config);
/* Writes stepcounter parameter settings /* Writes stepcounter parameter settings
@ -1380,18 +1388,19 @@ uint16_t bma423_stepcounter_set_parameter(const struct bma423_stepcounter_settin
/*! /*!
* @brief This API sets the sensitivity of wake up feature in the sensor * @brief This API sets the sensitivity of wake up feature in the sensor
*/ */
uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity, struct bma4_dev *dev) uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_WAKEUP_OFFSET; uint8_t index = BMA423_WAKEUP_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
feature_config[index] = BMA4_SET_BITSLICE(feature_config[index], feature_config[index] = BMA4_SET_BITSLICE(
BMA423_WAKEUP_SENS, sensitivity); feature_config[index], BMA423_WAKEUP_SENS, sensitivity);
/* Writes sensitivity settings in the sensor */ /* Writes sensitivity settings in the sensor */
rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, rslt |= bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev); BMA423_FEATURE_SIZE, dev);
@ -1409,18 +1418,20 @@ uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity, struct bma4_dev *dev
/*! /*!
* @brief This API gets the sensitivity of wake up feature in the sensor * @brief This API gets the sensitivity of wake up feature in the sensor
*/ */
uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity, struct bma4_dev *dev) uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity,
{ struct bma4_dev *dev) {
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {0};
uint8_t index = BMA423_WAKEUP_OFFSET; uint8_t index = BMA423_WAKEUP_OFFSET;
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
/* Extracts sensitivity data */ /* Extracts sensitivity data */
*sensitivity = BMA4_GET_BITSLICE(feature_config[index], BMA423_WAKEUP_SENS); *sensitivity =
BMA4_GET_BITSLICE(feature_config[index], BMA423_WAKEUP_SENS);
} }
} else { } else {
rslt = BMA4_E_INVALID_SENSOR; rslt = BMA4_E_INVALID_SENSOR;
@ -1436,15 +1447,17 @@ uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity, struct bma4_dev *de
* @brief This API is used to select single/double tap * @brief This API is used to select single/double tap
* feature in the sensor * feature in the sensor
*/ */
uint16_t bma423_tap_selection(const uint8_t tap_select, struct bma4_dev *dev) uint16_t bma423_tap_selection(const uint8_t tap_select, struct bma4_dev *dev) {
{
uint16_t rslt = BMA4_OK; uint16_t rslt = BMA4_OK;
uint8_t feature_config[BMA423_FEATURE_SIZE] = {0,}; uint8_t feature_config[BMA423_FEATURE_SIZE] = {
0,
};
uint8_t index = BMA423_WAKEUP_OFFSET; uint8_t index = BMA423_WAKEUP_OFFSET;
if (dev != NULL) { if (dev != NULL) {
if (dev->chip_id == BMA423_CHIP_ID) { if (dev->chip_id == BMA423_CHIP_ID) {
rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, BMA423_FEATURE_SIZE, dev); rslt = bma4_read_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config,
BMA423_FEATURE_SIZE, dev);
if (rslt == BMA4_OK) { if (rslt == BMA4_OK) {
feature_config[index] = BMA4_SET_BITSLICE(feature_config[index], feature_config[index] = BMA4_SET_BITSLICE(feature_config[index],
BMA423_TAP_SEL, tap_select); BMA423_TAP_SEL, tap_select);
@ -1463,8 +1476,7 @@ uint16_t bma423_tap_selection(const uint8_t tap_select, struct bma4_dev *dev)
/*! /*!
* @brief This API update the length for read and write. * @brief This API update the length for read and write.
*/ */
static void update_len(uint8_t *len, uint8_t feature, uint8_t enable) static void update_len(uint8_t *len, uint8_t feature, uint8_t enable) {
{
uint8_t length = BMA423_FEATURE_SIZE; uint8_t length = BMA423_FEATURE_SIZE;
if ((feature == BMA423_ANY_MOTION) || (feature == BMA423_NO_MOTION)) { if ((feature == BMA423_ANY_MOTION) || (feature == BMA423_NO_MOTION)) {
@ -1487,8 +1499,8 @@ static void update_len(uint8_t *len, uint8_t feature, uint8_t enable)
/*! /*!
* @brief This API enables the features of the sensor. * @brief This API enables the features of the sensor.
*/ */
static uint16_t feature_enable(uint8_t feature, uint8_t len, uint8_t *feature_config, struct bma4_dev *dev) static uint16_t feature_enable(uint8_t feature, uint8_t len,
{ uint8_t *feature_config, struct bma4_dev *dev) {
uint8_t index = 0; uint8_t index = 0;
uint16_t rslt; uint16_t rslt;
@ -1529,10 +1541,12 @@ static uint16_t feature_enable(uint8_t feature, uint8_t len, uint8_t *feature_co
if ((feature & BMA423_ANY_MOTION) > 0) { if ((feature & BMA423_ANY_MOTION) > 0) {
/* Enable anymotion */ /* Enable anymotion */
feature_config[index] = feature_config[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK); feature_config[index] =
feature_config[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK);
} else { } else {
/* Enable nomotion */ /* Enable nomotion */
feature_config[index] = feature_config[index] | BMA423_ANY_NO_MOTION_SEL_MSK; feature_config[index] =
feature_config[index] | BMA423_ANY_NO_MOTION_SEL_MSK;
} }
} }
@ -1545,8 +1559,8 @@ static uint16_t feature_enable(uint8_t feature, uint8_t len, uint8_t *feature_co
/*! /*!
* @brief This API disables the features of the sensor. * @brief This API disables the features of the sensor.
*/ */
static uint16_t feature_disable(uint8_t feature, uint8_t len, uint8_t *feature_config, struct bma4_dev *dev) static uint16_t feature_disable(uint8_t feature, uint8_t len,
{ uint8_t *feature_config, struct bma4_dev *dev) {
uint8_t index = 0; uint8_t index = 0;
uint16_t rslt; uint16_t rslt;
@ -1587,15 +1601,18 @@ static uint16_t feature_disable(uint8_t feature, uint8_t len, uint8_t *feature_c
if ((feature & BMA423_ANY_MOTION) > 0) { if ((feature & BMA423_ANY_MOTION) > 0) {
/* Disable anymotion */ /* Disable anymotion */
feature_config[index] = feature_config[index] | BMA423_ANY_NO_MOTION_SEL_MSK; feature_config[index] =
feature_config[index] | BMA423_ANY_NO_MOTION_SEL_MSK;
} else { } else {
/* Disable nomotion */ /* Disable nomotion */
feature_config[index] = feature_config[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK); feature_config[index] =
feature_config[index] & (~BMA423_ANY_NO_MOTION_SEL_MSK);
} }
/* Any/Nomotion axis enable bit pos. is 3 byte ahead of the /* Any/Nomotion axis enable bit pos. is 3 byte ahead of the
any/nomotion base address(0x00) */ any/nomotion base address(0x00) */
index = 3; index = 3;
feature_config[index] = feature_config[index] & (~BMA423_ANY_NO_MOTION_AXIS_EN_MSK); feature_config[index] =
feature_config[index] & (~BMA423_ANY_NO_MOTION_AXIS_EN_MSK);
} }
/* Write the configured settings in the sensor */ /* Write the configured settings in the sensor */
rslt = bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, len, dev); rslt = bma4_write_regs(BMA4_FEATURE_CONFIG_ADDR, feature_config, len, dev);
@ -1606,9 +1623,9 @@ static uint16_t feature_disable(uint8_t feature, uint8_t len, uint8_t *feature_c
/*! /*!
* @brief This API update the settings of step counter. * @brief This API update the settings of step counter.
*/ */
static void update_stepcounter_parameter(const struct bma423_stepcounter_settings *setting, static void
uint8_t index, uint8_t *feature_config) update_stepcounter_parameter(const struct bma423_stepcounter_settings *setting,
{ uint8_t index, uint8_t *feature_config) {
feature_config[index++] = BMA4_GET_LSB(setting->param1); feature_config[index++] = BMA4_GET_LSB(setting->param1);
feature_config[index++] = BMA4_GET_MSB(setting->param1); feature_config[index++] = BMA4_GET_MSB(setting->param1);
feature_config[index++] = BMA4_GET_LSB(setting->param2); feature_config[index++] = BMA4_GET_LSB(setting->param2);
@ -1665,8 +1682,9 @@ static void update_stepcounter_parameter(const struct bma423_stepcounter_setting
* @brief This API copy the settings of step counter into the * @brief This API copy the settings of step counter into the
* structure of bma423_stepcounter_settings, which is read from sensor. * structure of bma423_stepcounter_settings, which is read from sensor.
*/ */
static void extract_stepcounter_parameter(struct bma423_stepcounter_settings *setting, const uint16_t *data_p) static void
{ extract_stepcounter_parameter(struct bma423_stepcounter_settings *setting,
const uint16_t *data_p) {
setting->param1 = *(data_p++); setting->param1 = *(data_p++);
setting->param2 = *(data_p++); setting->param2 = *(data_p++);
setting->param3 = *(data_p++); setting->param3 = *(data_p++);

View File

@ -1,87 +1,87 @@
/* /*
* *
**************************************************************************** ****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
* *
* File : bma423.h * File : bma423.h
* *
* Date: 12 Oct 2017 * Date: 12 Oct 2017
* *
* Revision : 1.1.4 $ * Revision : 1.1.4 $
* *
* Usage: Sensor Driver for BMA423 sensor * Usage: Sensor Driver for BMA423 sensor
* *
**************************************************************************** ****************************************************************************
* *
* Disclaimer * Disclaimer
* *
* Common: * Common:
* Bosch Sensortec products are developed for the consumer goods industry. * Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid * They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the * product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a * express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining, * particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device * safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system * that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are * or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems. * not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and * The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use * his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser. * is the sole responsibility of the Purchaser.
* *
* The purchaser shall indemnify Bosch Sensortec from all third party * The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages, * claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of * arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by * the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in * Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims. * connection with such claims.
* *
* The purchaser must monitor the market for the purchased products, * The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec * particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents. * without delay of all security relevant incidents.
* *
* Engineering Samples are marked with an asterisk (*) or (e). * Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product * Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third * series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal * parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way * client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes * replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples. * no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify * By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering * Bosch Sensortec from all claims arising from the use of engineering
* samples. * samples.
* *
* Special: * Special:
* This software module (hereinafter called "Software") and any information * This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided * on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work. * free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following * The Software and Information is subject to the following
* terms and conditions: * terms and conditions:
* *
* The Software is specifically designed for the exclusive use for * The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience * Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the * and training. Do not use this Software if you do not have the
* proper experience or training. * proper experience or training.
* *
* This Software package is provided `` as is `` and without any expressed * This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties * or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose. * of merchantability and fitness for a particular purpose.
* *
* Bosch Sensortec and their representatives and agents deny any liability * Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment * for the functional impairment
* of this Software in terms of fitness, performance and safety. * of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable * Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as * for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law. * otherwise stipulated in mandatory applicable law.
* *
* The Information provided is believed to be accurate and reliable. * The Information provided is believed to be accurate and reliable.
* Bosch Sensortec assumes no responsibility for the consequences of use * Bosch Sensortec assumes no responsibility for the consequences of use
* of such Information nor for any infringement of patents or * of such Information nor for any infringement of patents or
* other rights of third parties which may result from its use. * other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or * No license is granted by implication or otherwise under any patent or
* patent rights of Bosch. Specifications mentioned in the Information are * patent rights of Bosch. Specifications mentioned in the Information are
* subject to change without notice. * subject to change without notice.
**************************************************************************/ **************************************************************************/
/*! \file bma423.h /*! \file bma423.h
\brief Sensor Driver for BMA423 sensor */ \brief Sensor Driver for BMA423 sensor */
#ifndef BMA423_H #ifndef BMA423_H
@ -109,7 +109,6 @@ extern "C" {
#define BMA423_CONFIG_ID_OFFSET UINT8_C(0x3C) #define BMA423_CONFIG_ID_OFFSET UINT8_C(0x3C)
#define BMA423_AXES_REMAP_OFFSET UINT8_C(0x3E) #define BMA423_AXES_REMAP_OFFSET UINT8_C(0x3E)
/**************************************************************/ /**************************************************************/
/**\name Remap Axes */ /**\name Remap Axes */
/**************************************************************/ /**************************************************************/
@ -385,7 +384,6 @@ uint16_t bma423_write_config_file(struct bma4_dev *dev);
*/ */
uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev); uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev);
/*! /*!
* @brief This API sets/unsets the user provided interrupt to either * @brief This API sets/unsets the user provided interrupt to either
* interrupt pin1 or pin2 in the sensor. * interrupt pin1 or pin2 in the sensor.
@ -422,7 +420,8 @@ uint16_t bma423_get_config_id(uint16_t *config_id, struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map, uint8_t enable, struct bma4_dev *dev); uint16_t bma423_map_interrupt(uint8_t int_line, uint16_t int_map,
uint8_t enable, struct bma4_dev *dev);
/*! /*!
* @brief This API reads the bma423 interrupt status from the sensor. * @brief This API reads the bma423 interrupt status from the sensor.
@ -479,8 +478,8 @@ uint16_t bma423_read_int_status(uint16_t *int_status, struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable, struct bma4_dev *dev); uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable,
struct bma4_dev *dev);
/*! /*!
* @brief This API performs x, y and z axis remapping in the sensor. * @brief This API performs x, y and z axis remapping in the sensor.
@ -492,7 +491,8 @@ uint16_t bma423_feature_enable(uint8_t feature, uint8_t enable, struct bma4_dev
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struct bma4_dev *dev); uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data,
struct bma4_dev *dev);
/*! /*!
* @brief This API reads the x, y and z axis remap data from the sensor. * @brief This API reads the x, y and z axis remap data from the sensor.
@ -505,8 +505,8 @@ uint16_t bma423_set_remap_axes(const struct bma423_axes_remap *remap_data, struc
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data, struct bma4_dev *dev); uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the watermark level for step counter * @brief This API sets the watermark level for step counter
@ -522,7 +522,8 @@ uint16_t bma423_get_remap_axes(struct bma423_axes_remap *remap_data, struct bma4
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm, struct bma4_dev *dev); uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm,
struct bma4_dev *dev);
/*! /*!
* @brief This API gets the water mark level set for step counter interrupt * @brief This API gets the water mark level set for step counter interrupt
@ -538,7 +539,8 @@ uint16_t bma423_step_counter_set_watermark(uint16_t step_counter_wm, struct bma4
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm, struct bma4_dev *dev); uint16_t bma423_step_counter_get_watermark(uint16_t *step_counter_wm,
struct bma4_dev *dev);
/*! /*!
* @brief This API resets the counted steps of step counter. * @brief This API resets the counted steps of step counter.
@ -613,7 +615,9 @@ uint16_t bma423_select_platform(uint8_t platform, struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *setting, struct bma4_dev *dev); uint16_t
bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *setting,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the parameter1 to parameter7 settings of the * @brief This API sets the parameter1 to parameter7 settings of the
@ -627,7 +631,8 @@ uint16_t bma423_stepcounter_get_parameter(struct bma423_stepcounter_settings *se
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_stepcounter_set_parameter(const struct bma423_stepcounter_settings *setting, struct bma4_dev *dev); uint16_t bma423_stepcounter_set_parameter(
const struct bma423_stepcounter_settings *setting, struct bma4_dev *dev);
/*! /*!
* @brief This API enables or disables the step detector feature in the * @brief This API enables or disables the step detector feature in the
@ -703,7 +708,9 @@ uint16_t bma423_anymotion_enable_axis(uint8_t axis, struct bma4_dev *dev);
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_motion, struct bma4_dev *dev); uint16_t
bma423_set_any_motion_config(const struct bma423_anymotion_config *any_motion,
struct bma4_dev *dev);
/*! @brief This API gets the configuration of any motion feature from /*! @brief This API gets the configuration of any motion feature from
* the sensor. * the sensor.
@ -741,7 +748,9 @@ uint16_t bma423_set_any_motion_config(const struct bma423_anymotion_config *any_
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion, struct bma4_dev *dev); uint16_t
bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion,
struct bma4_dev *dev);
/*! /*!
* @brief This API sets the sensitivity of wake up feature in the sensor * @brief This API sets the sensitivity of wake up feature in the sensor
@ -758,7 +767,8 @@ uint16_t bma423_get_any_motion_config(struct bma423_anymotion_config *any_motion
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity, struct bma4_dev *dev); uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity,
struct bma4_dev *dev);
/*! /*!
* @brief This API gets the sensitivity of wake up feature in the sensor * @brief This API gets the sensitivity of wake up feature in the sensor
@ -775,7 +785,8 @@ uint16_t bma423_wakeup_set_sensitivity(uint8_t sensitivity, struct bma4_dev *dev
* @retval 0 -> Success * @retval 0 -> Success
* @retval Any non zero value -> Fail * @retval Any non zero value -> Fail
*/ */
uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity, struct bma4_dev *dev); uint16_t bma423_wakeup_get_sensitivity(uint8_t *sensitivity,
struct bma4_dev *dev);
/*! /*!
* @brief This API is used to select single/double tap * @brief This API is used to select single/double tap

View File

@ -1,87 +1,87 @@
/* /*
* *
**************************************************************************** ****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
* *
* File : bma4_defs.h * File : bma4_defs.h
* *
* Date: 12 Oct 2017 * Date: 12 Oct 2017
* *
* Revision: 2.1.9 $ * Revision: 2.1.9 $
* *
* Usage: Sensor Driver for BMA4 family of sensors * Usage: Sensor Driver for BMA4 family of sensors
* *
**************************************************************************** ****************************************************************************
* *
* Disclaimer * Disclaimer
* *
* Common: * Common:
* Bosch Sensortec products are developed for the consumer goods industry. * Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid * They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the * product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a * express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining, * particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device * safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system * that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are * or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems. * not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and * The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use * his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser. * is the sole responsibility of the Purchaser.
* *
* The purchaser shall indemnify Bosch Sensortec from all third party * The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages, * claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of * arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by * the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in * Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims. * connection with such claims.
* *
* The purchaser must monitor the market for the purchased products, * The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec * particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents. * without delay of all security relevant incidents.
* *
* Engineering Samples are marked with an asterisk (*) or (e). * Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product * Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third * series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal * parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way * client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes * replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples. * no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify * By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering * Bosch Sensortec from all claims arising from the use of engineering
* samples. * samples.
* *
* Special: * Special:
* This software module (hereinafter called "Software") and any information * This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided * on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work. * free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following * The Software and Information is subject to the following
* terms and conditions: * terms and conditions:
* *
* The Software is specifically designed for the exclusive use for * The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience * Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the * and training. Do not use this Software if you do not have the
* proper experience or training. * proper experience or training.
* *
* This Software package is provided `` as is `` and without any expressed * This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties * or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose. * of merchantability and fitness for a particular purpose.
* *
* Bosch Sensortec and their representatives and agents deny any liability * Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment * for the functional impairment
* of this Software in terms of fitness, performance and safety. * of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable * Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as * for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law. * otherwise stipulated in mandatory applicable law.
* *
* The Information provided is believed to be accurate and reliable. * The Information provided is believed to be accurate and reliable.
* Bosch Sensortec assumes no responsibility for the consequences of use * Bosch Sensortec assumes no responsibility for the consequences of use
* of such Information nor for any infringement of patents or * of such Information nor for any infringement of patents or
* other rights of third parties which may result from its use. * other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or * No license is granted by implication or otherwise under any patent or
* patent rights of Bosch. Specifications mentioned in the Information are * patent rights of Bosch. Specifications mentioned in the Information are
* subject to change without notice. * subject to change without notice.
**************************************************************************/ **************************************************************************/
/*! \file bma4_defs.h /*! \file bma4_defs.h
\brief Sensor Driver for BMA4 family of sensors */ \brief Sensor Driver for BMA4 family of sensors */
#ifndef BMA4_DEFS_H__ #ifndef BMA4_DEFS_H__
@ -91,9 +91,9 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/types.h> #include <linux/types.h>
#else #else
#include <stdint.h>
#include <stddef.h>
#include <math.h> #include <math.h>
#include <stddef.h>
#include <stdint.h>
#endif #endif
/*********************************************************************/ /*********************************************************************/
@ -611,7 +611,6 @@
#define BMA4_MAG_DATA_RDY_INT UINT16_C(0x2000) #define BMA4_MAG_DATA_RDY_INT UINT16_C(0x2000)
#define BMA4_ACCEL_DATA_RDY_INT UINT16_C(0x8000) #define BMA4_ACCEL_DATA_RDY_INT UINT16_C(0x8000)
/**\name AKM POWER MODE SELECTION */ /**\name AKM POWER MODE SELECTION */
#define AKM_POWER_DOWN_MODE UINT8_C(0) #define AKM_POWER_DOWN_MODE UINT8_C(0)
#define AKM_SINGLE_MEAS_MODE UINT8_C(1) #define AKM_SINGLE_MEAS_MODE UINT8_C(1)
@ -660,7 +659,6 @@
/* BMA4_KELVIN_SCALED = 273.15 * 1000 */ /* BMA4_KELVIN_SCALED = 273.15 * 1000 */
#define BMA4_KELVIN_SCALED INT32_C(273150) #define BMA4_KELVIN_SCALED INT32_C(273150)
/**\name MAP BURST READ LENGTHS */ /**\name MAP BURST READ LENGTHS */
#define BMA4_AUX_READ_LEN_0 0 #define BMA4_AUX_READ_LEN_0 0
#define BMA4_AUX_READ_LEN_1 1 #define BMA4_AUX_READ_LEN_1 1
@ -672,11 +670,10 @@
#endif #endif
/**\name BIT SLICE GET AND SET FUNCTIONS */ /**\name BIT SLICE GET AND SET FUNCTIONS */
#define BMA4_GET_BITSLICE(regvar, bitname)\ #define BMA4_GET_BITSLICE(regvar, bitname) \
((regvar & bitname##_MSK) >> bitname##_POS) ((regvar & bitname##_MSK) >> bitname##_POS)
#define BMA4_SET_BITSLICE(regvar, bitname, val)\ #define BMA4_SET_BITSLICE(regvar, bitname, val) \
((regvar & ~bitname##_MSK) | \ ((regvar & ~bitname##_MSK) | ((val << bitname##_POS) & bitname##_MSK))
((val<<bitname##_POS)&bitname##_MSK))
#define BMA4_GET_DIFF(x, y) ((x) - (y)) #define BMA4_GET_DIFF(x, y) ((x) - (y))
#define BMA4_GET_LSB(var) (uint8_t)(var & BMA4_SET_LOW_BYTE) #define BMA4_GET_LSB(var) (uint8_t)(var & BMA4_SET_LOW_BYTE)
@ -685,8 +682,7 @@
#define BMA4_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK)) #define BMA4_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK))
#define BMA4_SET_BITS_POS_0(reg_data, bitname, data) \ #define BMA4_SET_BITS_POS_0(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \ ((reg_data & ~(bitname##_MSK)) | (data & bitname##_MSK))
(data & bitname##_MSK))
#define BMA4_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) #define BMA4_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
@ -695,7 +691,8 @@
* @brief Bus communication function pointer which should be mapped to * @brief Bus communication function pointer which should be mapped to
* the platform specific read and write functions of the user * the platform specific read and write functions of the user
*/ */
typedef uint16_t (*bma4_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *read_data, uint16_t len); typedef uint16_t (*bma4_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
uint8_t *read_data, uint16_t len);
/*! delay function pointer */ /*! delay function pointer */
typedef void (*bma4_delay_fptr_t)(uint32_t); typedef void (*bma4_delay_fptr_t)(uint32_t);
@ -705,10 +702,7 @@ typedef void (*bma4_delay_fptr_t)(uint32_t);
/******************************************************************************/ /******************************************************************************/
/*! @name Enum to define BMA4 variants */ /*! @name Enum to define BMA4 variants */
enum bma4_variant { enum bma4_variant { BMA42X_VARIANT = 1, BMA45X_VARIANT };
BMA42X_VARIANT = 1,
BMA45X_VARIANT
};
/**\name STRUCTURE DEFINITIONS*/ /**\name STRUCTURE DEFINITIONS*/
@ -859,7 +853,7 @@ struct bma4_int_pin_config {
}; };
/*! /*!
* @brief Accelerometer configuration structure */ * @brief Accelerometer configuration structure */
struct bma4_accel_config { struct bma4_accel_config {
/*! Output data rate in Hz */ /*! Output data rate in Hz */
uint8_t odr; uint8_t odr;

View File

@ -46,24 +46,24 @@
//display //display
#define DISPLAY_WIDTH 200 #define DISPLAY_WIDTH 200
#define DISPLAY_HEIGHT 200 #define DISPLAY_HEIGHT 200
//wifi // wifi
#define WIFI_AP_TIMEOUT 60 #define WIFI_AP_TIMEOUT 60
#define WIFI_AP_SSID "Watchy AP" #define WIFI_AP_SSID "Watchy AP"
//menu // menu
#define WATCHFACE_STATE -1 #define WATCHFACE_STATE -1
#define MAIN_MENU_STATE 0 #define MAIN_MENU_STATE 0
#define APP_STATE 1 #define APP_STATE 1
#define FW_UPDATE_STATE 2 #define FW_UPDATE_STATE 2
#define MENU_HEIGHT 25 #define MENU_HEIGHT 25
#define MENU_LENGTH 7 #define MENU_LENGTH 7
//set time // set time
#define SET_HOUR 0 #define SET_HOUR 0
#define SET_MINUTE 1 #define SET_MINUTE 1
#define SET_YEAR 2 #define SET_YEAR 2
#define SET_MONTH 3 #define SET_MONTH 3
#define SET_DAY 4 #define SET_DAY 4
#define HOUR_12_24 24 #define HOUR_12_24 24
//BLE OTA // BLE OTA
#define BLE_DEVICE_NAME "Watchy BLE OTA" #define BLE_DEVICE_NAME "Watchy BLE OTA"
#define WATCHFACE_NAME "Watchy 7 Segment" #define WATCHFACE_NAME "Watchy 7 Segment"
#define SOFTWARE_VERSION_MAJOR 1 #define SOFTWARE_VERSION_MAJOR 1
@ -71,6 +71,6 @@
#define SOFTWARE_VERSION_PATCH 0 #define SOFTWARE_VERSION_PATCH 0
#define HARDWARE_VERSION_MAJOR 1 #define HARDWARE_VERSION_MAJOR 1
#define HARDWARE_VERSION_MINOR 0 #define HARDWARE_VERSION_MINOR 0
//Versioning // Versioning
#define WATCHY_LIB_VER "1.4.0" #define WATCHY_LIB_VER "1.4.0"
#endif #endif

4
src/format.sh Normal file
View File

@ -0,0 +1,4 @@
#!/ bin / bash
STYLE_OPT = "{BasedOnStyle: llvm, AlignConsecutiveMacros: true, "
"AlignConsecutiveAssignments: true}" clang -
format-- style = "$STYLE_OPT" - i *