Skip to content

Commit

Permalink
SD card init and keyboard backlight preferences
Browse files Browse the repository at this point in the history
- basic SD card initialization
- keyboard backlight brightness is saved in the settings
  • Loading branch information
CoretechR committed Jan 12, 2025
1 parent 6152bfb commit b28d83f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions Platformio/hardware/ESP32/include_hal_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
#include "ESP32/sleep_hal_esp32.h"
#include "ESP32/tft_hal_esp32.h"
#include "ESP32/user_led_hal_esp32.h"
#include "ESP32/sd_card_hal_esp32.h"
10 changes: 8 additions & 2 deletions Platformio/hardware/ESP32/keypad_keys_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ void update_keyboardBrightness_HAL(void) {
ledcWrite(LEDC_CHANNEL_6, millis() - fadeInTimer);
}
else {
// normal mode, set full backlightBrightness
ledcWrite(LEDC_CHANNEL_6, keyboardBrightness);
// normal mode, set full backlightBrightness
// turn off PWM if backlight is at full brightness
if(keyboardBrightness < 255){
ledcWrite(LEDC_CHANNEL_6, keyboardBrightness);
}
else{
ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_6, 255);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Platformio/hardware/ESP32/preferencesStorage_hal_esp32.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Preferences.h>
#include "sleep_hal_esp32.h"
#include "tft_hal_esp32.h"
#include "keypad_keys_hal_esp32.h"

Preferences preferences;

Expand All @@ -18,6 +19,10 @@ void init_preferences_HAL(void) {
set_sleepTimeout_HAL(preferences.getUInt("slpTimeout"));
// from tft.h
set_backlightBrightness_HAL(preferences.getUChar("blBrightness"));
// from keyboard.h
#if(OMOTE_HARDWARE_REV >= 5)
set_keyboardBrightness_HAL(preferences.getUChar("kbBrightness"));
#endif
// from here
activeScene = std::string(preferences.getString("currentScene").c_str());
activeGUIname = std::string(preferences.getString("currentGUIname").c_str());
Expand All @@ -38,6 +43,10 @@ void save_preferences_HAL(void) {
// from tft.h
preferences.putUInt("slpTimeout", get_sleepTimeout_HAL());
preferences.putUChar("blBrightness", get_backlightBrightness_HAL());
// from keyboard.h
#if(OMOTE_HARDWARE_REV >= 5)
preferences.putUInt("kbBrightness", get_keyboardBrightness_HAL());
#endif
// from here
preferences.putString("currentScene", activeScene.c_str());
preferences.putString("currentGUIname", activeGUIname.c_str());
Expand Down
24 changes: 24 additions & 0 deletions Platformio/hardware/ESP32/sd_card_hal_esp32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <Arduino.h>
#include "sd_card_hal_esp32.h"
#include <SD.h>
#include <SPI.h>

uint8_t SD_EN_GPIO = 16;
uint8_t SD_CS_GPIO = 18;
uint8_t SD_MISO_GPIO = 7;
uint8_t SD_MOSI_GPIO = 17;
uint8_t SD_SCK_GPIO = 15;

void init_SD_HAL(void) {
pinMode(SD_EN_GPIO, OUTPUT);
digitalWrite(SD_EN_GPIO, LOW);
delay(10); // wait for the SD card to power up
SPI.begin(SD_SCK_GPIO, SD_MISO_GPIO, SD_MOSI_GPIO, SD_CS_GPIO);
if (!SD.begin(SD_CS_GPIO, SPI, 10000000)) { // 10 MHz
Serial.println("No SD card found.");
return;
}
else{
Serial.println("SD card initialized successfully.");
}
}
9 changes: 9 additions & 0 deletions Platformio/hardware/ESP32/sd_card_hal_esp32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

extern uint8_t SD_EN_GPIO;
extern uint8_t SD_CS_GPIO;
extern uint8_t SD_MISO_GPIO;
extern uint8_t SD_MOSI_GPIO;
extern uint8_t SD_SCK_GPIO;

void init_SD_HAL(void);
5 changes: 5 additions & 0 deletions Platformio/hardware/ESP32/sleep_hal_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "infrared_receiver_hal_esp32.h"
// turn off tft
#include "tft_hal_esp32.h"
// turn off SD card
#include "sd_card_hal_esp32.h"
// disconnect WiFi
#include "mqtt_hal_esp32.h"
// disconnect BLE keyboard
Expand Down Expand Up @@ -170,6 +172,9 @@ void enterSleep(){
#endif
digitalWrite(LCD_EN_GPIO, HIGH); // LCD logic off
digitalWrite(LCD_BL_GPIO, HIGH); // LCD backlight off
#if(OMOTE_HARDWARE_REV >= 5)
digitalWrite(SD_EN_GPIO, HIGH); // SD card off
#endif
// pinMode(CRG_STAT, INPUT); // Disable Pull-Up
pinMode(IR_RX_GPIO, INPUT); // force IR receiver pin to INPUT to prevent high current during sleep (additional 60 uA)
digitalWrite(IR_VCC_GPIO, LOW); // IR Receiver off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ void update_userled() {
update_userled_HAL();
}

// --- SD card ----------------------------------------------------------------
#if(OMOTE_HARDWARE_REV >= 5)
void init_SD_card(void) {
init_SD_HAL();
}
#endif

// --- battery ----------------------------------------------------------------
void init_battery(void) {
init_battery_HAL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ uint8_t get_keyboardBrightness();
void set_keyboardBrightness(uint8_t aKeyboardBrightness);
#endif

// --- SD card ----------------------------------------------------------------
#if(OMOTE_HARDWARE_REV >= 5)
void init_SD_card(void);
#endif

// --- IR sender --------------------------------------------------------------
void init_infraredSender(void);
enum IRprotocols {
Expand Down
4 changes: 4 additions & 0 deletions Platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ int main(int argc, char *argv[]) {
init_preferences();
// blinking led
init_userled();
// startup SD card
#if(OMOTE_HARDWARE_REV >= 5)
init_SD_card();
#endif

// setup IR sender
init_infraredSender();
Expand Down

0 comments on commit b28d83f

Please sign in to comment.