diff --git a/.gitignore b/.gitignore index 26745cb..43e9fce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store ~/.DS_Store */.DS_Store examples/Basics/.DS_Store diff --git a/src/AXP.h b/src/AXP.h index da429cf..a48d3e1 100644 --- a/src/AXP.h +++ b/src/AXP.h @@ -31,12 +31,14 @@ uint16_t Read16bit(uint8_t Addr); uint32_t Read24bit(uint8_t Addr); uint32_t Read32bit(uint8_t Addr); void ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff); -bool writeRegister8Array(const std::uint8_t *reg_data_array, std::size_t length); +bool writeRegister8Array(const uint8_t *reg_data_array, + size_t length); -uint8_t calcVoltageData(uint16_t value, uint16_t maxv, uint16_t minv, uint16_t step); +uint8_t calcVoltageData(uint16_t value, uint16_t maxv, uint16_t minv, + uint16_t step); class AXP { -public: + public: enum pmic_t { pmic_unknown = 0, pmic_axp192, pmic_axp2101 }; AXP192 axp192; @@ -78,8 +80,7 @@ class AXP { float GetCoulombData(void); float GetBatteryLevel(void); void PowerOff(void); - void SetSleep(void) - { + void SetSleep(void) { PowerOff(); }; @@ -128,15 +129,11 @@ class AXP { void SetPeripherialsPower(uint8_t state); void SetVibration(uint8_t state); - /// set battery charge enable. - /// @param enable true=enable / false=disable - void SetBatteryCharge(bool enable); - pmic_t getPmicType() const - { + pmic_t getPmicType() const { return _pmic; } -private: + private: pmic_t _pmic; }; diff --git a/src/AXP192.cpp b/src/AXP192.cpp index 8c9e549..9db8fa9 100644 --- a/src/AXP192.cpp +++ b/src/AXP192.cpp @@ -1,12 +1,10 @@ #include "AXP192.h" #include "AXP.h" -AXP192::AXP192() -{ +AXP192::AXP192() { } -void AXP192::begin() -{ +void AXP192::begin() { // Wire1.begin(21, 22); // Wire1.setClock(400000); @@ -72,8 +70,7 @@ void AXP192::begin() } } -void AXP192::ScreenBreath(int brightness) -{ +void AXP192::ScreenBreath(int brightness) { if (brightness >= 100) brightness = 100; else if (brightness < 0) @@ -82,8 +79,7 @@ void AXP192::ScreenBreath(int brightness) SetLcdVoltage((uint16_t)vol); } -bool AXP192::GetBatState() -{ +bool AXP192::GetBatState() { if (Read8bit(0x01) | 0x20) return true; else @@ -98,38 +94,31 @@ bool AXP192::GetBatState() // get discharge data: uint32_t GetCoulombdischargeData(void); // get coulomb val affter calculation: float GetCoulombData(void); //------------------------------------------ -void AXP192::EnableCoulombcounter(void) -{ +void AXP192::EnableCoulombcounter(void) { Write1Byte(0xB8, 0x80); } -void AXP192::DisableCoulombcounter(void) -{ +void AXP192::DisableCoulombcounter(void) { Write1Byte(0xB8, 0x00); } -void AXP192::StopCoulombcounter(void) -{ +void AXP192::StopCoulombcounter(void) { Write1Byte(0xB8, 0xC0); } -void AXP192::ClearCoulombcounter(void) -{ +void AXP192::ClearCoulombcounter(void) { Write1Byte(0xB8, 0xA0); } -uint32_t AXP192::GetCoulombchargeData(void) -{ +uint32_t AXP192::GetCoulombchargeData(void) { return Read32bit(0xB0); } -uint32_t AXP192::GetCoulombdischargeData(void) -{ +uint32_t AXP192::GetCoulombdischargeData(void) { return Read32bit(0xB4); } -float AXP192::GetCoulombData(void) -{ +float AXP192::GetCoulombData(void) { uint32_t coin = 0; uint32_t coout = 0; @@ -144,19 +133,16 @@ float AXP192::GetCoulombData(void) } // Cut all power, except for LDO1 (RTC) -void AXP192::PowerOff(void) -{ +void AXP192::PowerOff(void) { Write1Byte(0x32, Read8bit(0x32) | 0b10000000); } -void AXP192::SetAdcState(bool state) -{ +void AXP192::SetAdcState(bool state) { // Enable / Disable all ADCs Write1Byte(0x82, state ? 0xff : 0x00); } -void AXP192::PrepareToSleep(void) -{ +void AXP192::PrepareToSleep(void) { // Disable ADCs SetAdcState(false); @@ -168,15 +154,14 @@ void AXP192::PrepareToSleep(void) } // Get current battery level -float AXP192::GetBatteryLevel(void) -{ - const float batVoltage = GetBatVoltage(); - const float batPercentage = (batVoltage < 3.248088) ? (0) : (batVoltage - 3.120712) * 100; +float AXP192::GetBatteryLevel(void) { + const float batVoltage = GetBatVoltage(); + const float batPercentage = + (batVoltage < 3.248088) ? (0) : (batVoltage - 3.120712) * 100; return (batPercentage <= 100) ? batPercentage : 100; } -void AXP192::RestoreFromLightSleep(void) -{ +void AXP192::RestoreFromLightSleep(void) { // Turn LCD backlight on SetDCDC3(true); @@ -187,8 +172,7 @@ void AXP192::RestoreFromLightSleep(void) SetAdcState(true); } -uint8_t AXP192::GetWarningLeve(void) -{ +uint8_t AXP192::GetWarningLeve(void) { Wire1.beginTransmission(AXP192_ADDR); Wire1.write(0x47); Wire1.endTransmission(); @@ -198,8 +182,7 @@ uint8_t AXP192::GetWarningLeve(void) } // -- sleep -void AXP192::DeepSleep(uint64_t time_in_us) -{ +void AXP192::DeepSleep(uint64_t time_in_us) { PrepareToSleep(); if (time_in_us > 0) { @@ -212,8 +195,7 @@ void AXP192::DeepSleep(uint64_t time_in_us) // Never reached - after deep sleep ESP32 restarts } -void AXP192::LightSleep(uint64_t time_in_us) -{ +void AXP192::LightSleep(uint64_t time_in_us) { PrepareToSleep(); if (time_in_us > 0) { @@ -226,102 +208,87 @@ void AXP192::LightSleep(uint64_t time_in_us) RestoreFromLightSleep(); } -uint8_t AXP192::GetWarningLevel(void) -{ +uint8_t AXP192::GetWarningLevel(void) { return Read8bit(0x47) & 0x01; } -float AXP192::GetBatVoltage() -{ +float AXP192::GetBatVoltage() { float ADCLSB = 1.1 / 1000.0; uint16_t ReData = Read12Bit(0x78); return ReData * ADCLSB; } -float AXP192::GetBatCurrent() -{ +float AXP192::GetBatCurrent() { float ADCLSB = 0.5; uint16_t CurrentIn = Read13Bit(0x7A); uint16_t CurrentOut = Read13Bit(0x7C); return (CurrentIn - CurrentOut) * ADCLSB; } -float AXP192::GetVinVoltage() -{ +float AXP192::GetVinVoltage() { float ADCLSB = 1.7 / 1000.0; uint16_t ReData = Read12Bit(0x56); return ReData * ADCLSB; } -float AXP192::GetVinCurrent() -{ +float AXP192::GetVinCurrent() { float ADCLSB = 0.625; uint16_t ReData = Read12Bit(0x58); return ReData * ADCLSB; } -float AXP192::GetVBusVoltage() -{ +float AXP192::GetVBusVoltage() { float ADCLSB = 1.7 / 1000.0; uint16_t ReData = Read12Bit(0x5A); return ReData * ADCLSB; } -float AXP192::GetVBusCurrent() -{ +float AXP192::GetVBusCurrent() { float ADCLSB = 0.375; uint16_t ReData = Read12Bit(0x5C); return ReData * ADCLSB; } -float AXP192::GetTempInAXP192() -{ +float AXP192::GetTempInAXP192() { float ADCLSB = 0.1; const float OFFSET_DEG_C = -144.7; uint16_t ReData = Read12Bit(0x5E); return OFFSET_DEG_C + ReData * ADCLSB; } -float AXP192::GetBatPower() -{ +float AXP192::GetBatPower() { float VoltageLSB = 1.1; float CurrentLCS = 0.5; uint32_t ReData = Read24bit(0x70); return VoltageLSB * CurrentLCS * ReData / 1000.0; } -float AXP192::GetBatChargeCurrent() -{ +float AXP192::GetBatChargeCurrent() { float ADCLSB = 0.5; uint16_t ReData = Read12Bit(0x7A); return ReData * ADCLSB; } -float AXP192::GetAPSVoltage() -{ +float AXP192::GetAPSVoltage() { float ADCLSB = 1.4 / 1000.0; uint16_t ReData = Read12Bit(0x7E); return ReData * ADCLSB; } -float AXP192::GetBatCoulombInput() -{ +float AXP192::GetBatCoulombInput() { uint32_t ReData = Read32bit(0xB0); return ReData * 65536 * 0.5 / 3600 / 25.0; } -float AXP192::GetBatCoulombOut() -{ +float AXP192::GetBatCoulombOut() { uint32_t ReData = Read32bit(0xB4); return ReData * 65536 * 0.5 / 3600 / 25.0; } -void AXP192::SetCoulombClear() -{ +void AXP192::SetCoulombClear() { Write1Byte(0xB8, 0x20); } -void AXP192::SetLDO2(bool State) -{ +void AXP192::SetLDO2(bool State) { uint8_t buf = Read8bit(0x12); if (State == true) buf = (1 << 2) | buf; @@ -330,8 +297,7 @@ void AXP192::SetLDO2(bool State) Write1Byte(0x12, buf); } -void AXP192::SetDCDC3(bool State) -{ +void AXP192::SetDCDC3(bool State) { uint8_t buf = Read8bit(0x12); if (State == true) buf = (1 << 1) | buf; @@ -340,25 +306,20 @@ void AXP192::SetDCDC3(bool State) Write1Byte(0x12, buf); } -uint8_t AXP192::AXPInState() -{ +uint8_t AXP192::AXPInState() { return Read8bit(0x00); } -bool AXP192::isACIN() -{ +bool AXP192::isACIN() { return (Read8bit(0x00) & 0x80) ? true : false; } -bool AXP192::isCharging() -{ +bool AXP192::isCharging() { return (Read8bit(0x00) & 0x04) ? true : false; } -bool AXP192::isVBUS() -{ +bool AXP192::isVBUS() { return (Read8bit(0x00) & 0x20) ? true : false; } -void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage) -{ +void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage) { uint8_t vdata = calcVoltageData(voltage, 3300, 1800, 100) & 0x0F; switch (number) { // uint8_t reg, data; @@ -372,8 +333,7 @@ void AXP192::SetLDOVoltage(uint8_t number, uint16_t voltage) } /// @param number 0=DCDC1 / 1=DCDC2 / 2=DCDC3 -void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) -{ +void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) { uint8_t addr; uint8_t vdata; if (number > 2) return; @@ -398,22 +358,19 @@ void AXP192::SetDCVoltage(uint8_t number, uint16_t voltage) Write1Byte(addr, (Read8bit(addr) & 0x80) | vdata); } -void AXP192::SetESPVoltage(uint16_t voltage) -{ +void AXP192::SetESPVoltage(uint16_t voltage) { if (voltage >= 3000 && voltage <= 3400) { SetDCVoltage(0, voltage); } } -void AXP192::SetLcdVoltage(uint16_t voltage) -{ +void AXP192::SetLcdVoltage(uint16_t voltage) { if (voltage >= 2500 && voltage <= 3300) { SetDCVoltage(2, voltage); } } -void AXP192::SetLDOEnable(uint8_t number, bool state) -{ +void AXP192::SetLDOEnable(uint8_t number, bool state) { uint8_t mark = 0x01; if ((number < 2) || (number > 3)) return; @@ -425,8 +382,7 @@ void AXP192::SetLDOEnable(uint8_t number, bool state) } } -void AXP192::SetLCDRSet(bool state) -{ +void AXP192::SetLCDRSet(bool state) { uint8_t reg_addr = 0x96; uint8_t gpio_bit = 0x02; uint8_t data; @@ -444,8 +400,7 @@ void AXP192::SetLCDRSet(bool state) // Select source for BUS_5V // 0 : use internal boost // 1 : powered externally -void AXP192::SetBusPowerMode(uint8_t state) -{ +void AXP192::SetBusPowerMode(uint8_t state) { uint8_t data; if (state == 0) { // Set GPIO to 3.3V (LDO OUTPUT mode) @@ -469,8 +424,7 @@ void AXP192::SetBusPowerMode(uint8_t state) } } -void AXP192::SetLed(uint8_t state) -{ +void AXP192::SetLed(uint8_t state) { uint8_t reg_addr = 0x94; uint8_t data; data = Read8bit(reg_addr); @@ -485,8 +439,7 @@ void AXP192::SetLed(uint8_t state) } // set led state(GPIO high active,set 1 to enable amplifier) -void AXP192::SetSpkEnable(uint8_t state) -{ +void AXP192::SetSpkEnable(uint8_t state) { uint8_t reg_addr = 0x94; uint8_t gpio_bit = 0x04; uint8_t data; @@ -501,16 +454,14 @@ void AXP192::SetSpkEnable(uint8_t state) Write1Byte(reg_addr, data); } -void AXP192::SetCHGCurrent(uint8_t state) -{ +void AXP192::SetCHGCurrent(uint8_t state) { uint8_t data = Read8bit(0x33); data &= 0xf0; data = data | (state & 0x0f); Write1Byte(0x33, data); } -void AXP192::SetPeripherialsPower(uint8_t state) -{ +void AXP192::SetPeripherialsPower(uint8_t state) { if (!state) Write1Byte(0x10, Read8bit(0x10) & 0XFB); else if (state) @@ -518,7 +469,6 @@ void AXP192::SetPeripherialsPower(uint8_t state) // uint8_t data; // Set EXTEN to enable 5v boost } - void AXP192::SetBatteryCharge(bool enable) { uint8_t data = Read8bit(0x33); diff --git a/src/AXP192.h b/src/AXP192.h index 3209226..fe0235e 100644 --- a/src/AXP192.h +++ b/src/AXP192.h @@ -7,7 +7,7 @@ #define AXP192_ADDR 0X34 class AXP192 { -public: + public: enum CHGCurrent { kCHG_100mA = 0, kCHG_190mA, @@ -85,7 +85,6 @@ class AXP192 { void SetSpkEnable(uint8_t state); void SetCHGCurrent(uint8_t state); void SetPeripherialsPower(uint8_t state); - /// set battery charge enable. /// @param enable true=enable / false=disable void SetBatteryCharge(bool enable); diff --git a/src/M5Display.cpp b/src/M5Display.cpp index 55572d8..ffd83bc 100644 --- a/src/M5Display.cpp +++ b/src/M5Display.cpp @@ -2,6 +2,7 @@ #ifdef M5Stack_M5Core2 #include +#include #endif /* M5Stack_M5Core2 */ #define BLK_PWM_CHANNEL 7 // LEDC_CHANNEL_7 @@ -19,7 +20,7 @@ void M5Display::begin() { fillScreen(0); // Init the back-light LED PWM - ledcSetup(BLK_PWM_CHANNEL, 44100, 8); + ledcAttach(TFT_BL, 44100, 8); // ledcAttachPin(TFT_BL, BLK_PWM_CHANNEL); ledcWrite(BLK_PWM_CHANNEL, 80); } @@ -254,7 +255,7 @@ typedef struct { uint16_t outHeight; } jpg_file_decoder_t; -static uint32_t jpgReadFile(JDEC *decoder, uint8_t *buf, uint32_t len) { +static UINT jpgReadFile(JDEC *decoder, uint8_t *buf, UINT len) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; File *file = (File *)jpeg->src; if (buf) { @@ -265,7 +266,7 @@ static uint32_t jpgReadFile(JDEC *decoder, uint8_t *buf, uint32_t len) { return len; } -static uint32_t jpgRead(JDEC *decoder, uint8_t *buf, uint32_t len) { +static UINT jpgRead(JDEC *decoder, uint8_t *buf, UINT len) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; if (buf) { memcpy(buf, (const uint8_t *)jpeg->src + jpeg->index, len); @@ -274,7 +275,7 @@ static uint32_t jpgRead(JDEC *decoder, uint8_t *buf, uint32_t len) { return len; } -static uint32_t jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { +static UINT jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; uint16_t x = rect->left; uint16_t y = rect->top; @@ -348,7 +349,7 @@ static uint32_t jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { } static bool jpgDecode(jpg_file_decoder_t *jpeg, - uint32_t (*reader)(JDEC *, uint8_t *, uint32_t)) { + UINT (*reader)(JDEC *, uint8_t *, UINT)) { static uint8_t work[3100]; JDEC decoder; diff --git a/src/Speaker.cpp b/src/Speaker.cpp index ad877f6..29fdc49 100644 --- a/src/Speaker.cpp +++ b/src/Speaker.cpp @@ -28,7 +28,7 @@ bool Speaker::InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S .use_apll = false, .tx_desc_auto_clear = true, .fixed_mclk = -1, - .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT, + .mclk_multiple = I2S_MCLK_MULTIPLE_256, .bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT, }; if (mode == MODE_MIC) { diff --git a/src/utility/In_eSPI.h b/src/utility/In_eSPI.h index 1d23755..83cbaf8 100644 --- a/src/utility/In_eSPI.h +++ b/src/utility/In_eSPI.h @@ -14,11 +14,10 @@ // Stop fonts etc being loaded multiple times #ifndef _In_eSPIH_ #define _In_eSPIH_ - +#include "soc/gpio_struct.h" #define TFT_ESPI_VERSION "1.4.21" // #define ESP32 //Just used to test ESP32 options -#include "hal/gpio_ll.h" // Include header file that defines the fonts loaded, the TFT drivers // available and the pins to be used @@ -147,8 +146,12 @@ GPIO.out1_w1tc.val = (1 << (TFT_DC - 32)); \ GPIO.out1_w1ts.val = (1 << (TFT_DC - 32)) #else -#define DC_C GPIO.out1_w1tc.val = (1 << (TFT_DC - 32)) //;GPIO.out1_w1tc.val = (1 << (TFT_DC - 32)) -#define DC_D GPIO.out1_w1ts.val = (1 << (TFT_DC - 32)) //;GPIO.out1_w1ts.val = (1 << (TFT_DC - 32)) +#define DC_C \ + GPIO.out1_w1tc.val = \ + (1 << (TFT_DC - 32)) //;GPIO.out1_w1tc.val = (1 << (TFT_DC - 32)) +#define DC_D \ + GPIO.out1_w1ts.val = \ + (1 << (TFT_DC - 32)) //;GPIO.out1_w1ts.val = (1 << (TFT_DC - 32)) #endif #else #if TFT_DC >= 0 @@ -210,7 +213,9 @@ #define CS_L \ GPIO.out1_w1tc.val = (1 << (TFT_CS - 32)); \ GPIO.out1_w1tc.val = (1 << (TFT_CS - 32)) -#define CS_H GPIO.out1_w1ts.val = (1 << (TFT_CS - 32)) //;GPIO.out1_w1ts.val = (1 << (TFT_CS - 32)) +#define CS_H \ + GPIO.out1_w1ts.val = \ + (1 << (TFT_CS - 32)) //;GPIO.out1_w1ts.val = (1 << (TFT_CS - 32)) #endif #else #if TFT_CS >= 0 @@ -304,9 +309,9 @@ #if defined(ESP32) && defined(ESP32_PARALLEL) // Mask for the 8 data bits to set pin directions -#define dir_mask \ - ((1 << TFT_D0) | (1 << TFT_D1) | (1 << TFT_D2) | (1 << TFT_D3) | (1 << TFT_D4) | (1 << TFT_D5) | (1 << TFT_D6) | \ - (1 << TFT_D7)) +#define dir_mask \ + ((1 << TFT_D0) | (1 << TFT_D1) | (1 << TFT_D2) | (1 << TFT_D3) | \ + (1 << TFT_D4) | (1 << TFT_D5) | (1 << TFT_D6) | (1 << TFT_D7)) // Data bits and the write line are cleared to 0 in one step #define clr_mask (dir_mask | (1 << TFT_WR)) @@ -379,7 +384,8 @@ // #define RD_H digitalWrite(TFT_WR, HIGH) #endif -#elif defined(ILI9488_DRIVER) // 16 bit colour converted to 3 bytes for 18 bit RGB +#elif defined( \ + ILI9488_DRIVER) // 16 bit colour converted to 3 bytes for 18 bit RGB // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) @@ -419,32 +425,36 @@ // to avoid the function call overhead // Write 8 bits -#define tft_Write_8(C) \ - WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 8 - 1); \ - WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ - SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ - while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR); +#define tft_Write_8(C) \ + WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 8 - 1); \ + WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ + SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ + while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR) \ + ; // Write 16 bits with corrected endianess for 16 bit colours #define tft_Write_16(C) \ WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 16 - 1); \ WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C << 8 | C >> 8); \ SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ - while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR); + while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR) \ + ; // Write 16 bits -#define tft_Write_16S(C) \ - WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 16 - 1); \ - WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ - SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ - while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR); +#define tft_Write_16S(C) \ + WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 16 - 1); \ + WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ + SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ + while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR) \ + ; // Write 32 bits -#define tft_Write_32(C) \ - WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 32 - 1); \ - WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ - SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ - while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR); +#define tft_Write_32(C) \ + WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 32 - 1); \ + WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), C); \ + SET_PERI_REG_MASK(SPI_CMD_REG(SPI_PORT), SPI_USR); \ + while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT)) & SPI_USR) \ + ; #endif @@ -550,19 +560,20 @@ #endif // #ifdef LOAD_GFXFF // These enumerate the text plotting alignment (reference datum point) -#define TL_DATUM 0 // Top left (default) -#define TC_DATUM 1 // Top centre -#define TR_DATUM 2 // Top right -#define ML_DATUM 3 // Middle left -#define CL_DATUM 3 // Centre left, same as above -#define MC_DATUM 4 // Middle centre -#define CC_DATUM 4 // Centre centre, same as above -#define MR_DATUM 5 // Middle right -#define CR_DATUM 5 // Centre right, same as above -#define BL_DATUM 6 // Bottom left -#define BC_DATUM 7 // Bottom centre -#define BR_DATUM 8 // Bottom right -#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on) +#define TL_DATUM 0 // Top left (default) +#define TC_DATUM 1 // Top centre +#define TR_DATUM 2 // Top right +#define ML_DATUM 3 // Middle left +#define CL_DATUM 3 // Centre left, same as above +#define MC_DATUM 4 // Middle centre +#define CC_DATUM 4 // Centre centre, same as above +#define MR_DATUM 5 // Middle right +#define CR_DATUM 5 // Centre right, same as above +#define BL_DATUM 6 // Bottom left +#define BC_DATUM 7 // Bottom centre +#define BR_DATUM 8 // Bottom right +#define L_BASELINE \ + 9 // Left character baseline (Line the 'A' character would sit on) #define C_BASELINE 10 // Centre character baseline #define R_BASELINE 11 // Right character baseline @@ -594,8 +605,7 @@ // Swap any type template -static inline void swap_coord(T &a, T &b) -{ +static inline void swap_coord(T &a, T &b) { T t = a; a = b; b = t; @@ -724,7 +734,7 @@ typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y); // Class functions and variables class TFT_eSPI : public Print { -public: + public: TFT_eSPI(int16_t _W = TFT_WIDTH, int16_t _H = TFT_HEIGHT); void init(uint8_t tc = TAB_COLOUR), @@ -734,18 +744,22 @@ class TFT_eSPI : public Print { // These are virtual so the TFT_eSprite class can override them with sprite // specific functions virtual void drawPixel(int32_t x, int32_t y, uint32_t color), - drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size), - drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color), + drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, + uint8_t size), + drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, + uint32_t color), drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color), drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color), fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); - virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font), - drawChar(uint16_t uniCode, int32_t x, int32_t y), height(void), width(void); + virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, + uint8_t font), + drawChar(uint16_t uniCode, int32_t x, int32_t y), height(void), + width(void); // The TFT_eSprite class inherits the following functions - void setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye), pushColor(uint16_t color), - pushColor(uint16_t color, uint32_t len), + void setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye), + pushColor(uint16_t color), pushColor(uint16_t color, uint32_t len), pushColors(uint16_t *data, uint32_t len, bool swap = true), // With byte swap option pushColors(uint8_t *data, uint32_t len), @@ -753,32 +767,45 @@ class TFT_eSPI : public Print { fillScreen(uint32_t color); void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color), - drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color), - fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color), + drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, + int32_t radius, uint32_t color), + fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, + int32_t radius, uint32_t color), setRotation(uint8_t r), invertDisplay(boolean i), drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color), - drawCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, uint32_t color), + drawCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, + uint32_t color), fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color), - fillCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, int32_t delta, uint32_t color), - - drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color), - fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color), - - drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color), - fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color), - - drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color), - drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color), - drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, - uint16_t bgcolor), + fillCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, + int32_t delta, uint32_t color), + + drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, + uint16_t color), + fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, + uint16_t color), + + drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, + int32_t y2, uint32_t color), + fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, + int32_t y2, uint32_t color), + + drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, + int16_t h, uint16_t color), + drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, + int16_t h, uint16_t color), + drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, + int16_t h, uint16_t fgcolor, uint16_t bgcolor), setBitmapColor(uint16_t fgcolor, uint16_t bgcolor), // For 1bpp sprites - setPivot(int16_t x, int16_t y), setCursor(int16_t x, int16_t y), setCursor(int16_t x, int16_t y, uint8_t font), - setTextColor(uint16_t color), setTextColor(uint16_t fgcolor, uint16_t bgcolor), setTextSize(uint8_t size), + setPivot(int16_t x, int16_t y), setCursor(int16_t x, int16_t y), + setCursor(int16_t x, int16_t y, uint8_t font), + setTextColor(uint16_t color), + setTextColor(uint16_t fgcolor, uint16_t bgcolor), + setTextSize(uint8_t size), - setTextWrap(boolean wrapX, boolean wrapY = false), setTextDatum(uint8_t datum), - setTextPadding(uint16_t x_width), + setTextWrap(boolean wrapX, boolean wrapY = false), + setTextDatum(uint8_t datum), setTextPadding(uint16_t x_width), #ifdef LOAD_GFXFF setFreeFont(const GFXfont *f = NULL), setTextFont(uint8_t font), @@ -805,16 +832,22 @@ class TFT_eSPI : public Print { void pushRect(int32_t x0, int32_t y0, int32_t w, int32_t h, uint16_t *data); // These are used to render images or sprites stored in RAM arrays - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint16_t *data); - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint16_t *data, uint16_t transparent); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, + uint16_t *data); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint16_t *data, + uint16_t transparent); // These are used to render images stored in FLASH (PROGMEM) - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent); - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, const uint16_t *data); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, + const uint16_t *data, uint16_t transparent); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, + const uint16_t *data); // These are used by pushSprite for 1 and 8 bit colours - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true); - void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data, uint8_t transparent, bool bpp8 = true); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data, + bool bpp8 = true); + void pushImage(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data, + uint8_t transparent, bool bpp8 = true); // Swap the byte order for pushImage() - corrects endianness void setSwapBytes(bool swap); @@ -824,7 +857,8 @@ class TFT_eSPI : public Print { // PC for documentation purposes It reads a screen area and returns the RGB // 8 bit colour values of each pixel Set w and h to 1 to read 1 pixel's // colour. The data buffer must be at least w * h * 3 bytes - void readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data); + void readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, + uint8_t *data); uint8_t getRotation(void), getTextDatum(void), color16to8(uint16_t color565); // Convert 16 bit colour to 8 bits @@ -835,41 +869,50 @@ class TFT_eSPI : public Print { uint16_t fontsLoaded(void), color565(uint8_t red, uint8_t green, - uint8_t blue), // Convert 8 bit red, green and blue to 16 bits + uint8_t blue), // Convert 8 bit red, green and blue to 16 bits color8to16(uint8_t color332); // Convert 8 bit colour to 16 bits int16_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font), drawNumber(long long_num, int32_t poX, int32_t poY), - drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY, uint8_t font), + drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY, + uint8_t font), drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY), // Handle char arrays drawString(const char *string, int32_t poX, int32_t poY, uint8_t font), drawString(const char *string, int32_t poX, int32_t poY), - drawCentreString(const char *string, int32_t dX, int32_t poY, - uint8_t font), // Deprecated, use setTextDatum() and drawString() - drawRightString(const char *string, int32_t dX, int32_t poY, - uint8_t font), // Deprecated, use setTextDatum() and drawString() + drawCentreString( + const char *string, int32_t dX, int32_t poY, + uint8_t font), // Deprecated, use setTextDatum() and drawString() + drawRightString( + const char *string, int32_t dX, int32_t poY, + uint8_t font), // Deprecated, use setTextDatum() and drawString() // Handle String type - drawString(const String &string, int32_t poX, int32_t poY, uint8_t font), + drawString(const String &string, int32_t poX, int32_t poY, + uint8_t font), drawString(const String &string, int32_t poX, int32_t poY), - drawCentreString(const String &string, int32_t dX, int32_t poY, - uint8_t font), // Deprecated, use setTextDatum() and drawString() - drawRightString(const String &string, int32_t dX, int32_t poY, - uint8_t font); // Deprecated, use setTextDatum() and drawString() - - int16_t textWidth(const char *string, uint8_t font), textWidth(const char *string), - textWidth(const String &string, uint8_t font), textWidth(const String &string), fontHeight(int16_t font), + drawCentreString( + const String &string, int32_t dX, int32_t poY, + uint8_t font), // Deprecated, use setTextDatum() and drawString() + drawRightString( + const String &string, int32_t dX, int32_t poY, + uint8_t font); // Deprecated, use setTextDatum() and drawString() + + int16_t textWidth(const char *string, uint8_t font), + textWidth(const char *string), + textWidth(const String &string, uint8_t font), + textWidth(const String &string), fontHeight(int16_t font), fontHeight(void); void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h); // Compatibility additions void startWrite(void); // Begin SPI transaction - void writeColor(uint16_t color, - uint32_t len); // Write colours without transaction overhead - void endWrite(void); // End SPI transaction + void writeColor( + uint16_t color, + uint32_t len); // Write colours without transaction overhead + void endWrite(void); // End SPI transaction uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining); uint16_t decodeUTF8(uint8_t c); @@ -890,7 +933,8 @@ class TFT_eSPI : public Print { void setAttribute(uint8_t id = 0, uint8_t a = 0); uint8_t getAttribute(uint8_t id = 0); - void getSetup(setup_t &tft_settings); // Sketch provides the instance to populate + void getSetup( + setup_t &tft_settings); // Sketch provides the instance to populate static SPIClass &getSPIinstance(void); @@ -910,7 +954,7 @@ class TFT_eSPI : public Print { uint8_t decoderState = 0; // UTF8 decoder state uint16_t decoderBuffer; // Unicode code-point buffer -private: + private: inline void spi_begin() __attribute__((always_inline)); inline void spi_end() __attribute__((always_inline)); @@ -932,7 +976,7 @@ class TFT_eSPI : public Print { uint32_t lastColor = 0xFFFF; -protected: + protected: getColorCallback getColor = nullptr; uint8_t _smooth_bpp; int32_t win_xe, win_ye; @@ -949,15 +993,15 @@ class TFT_eSPI : public Print { bool isDigits; // adjust bounding box for numbers to reduce visual jiggling bool textwrapX, - textwrapY; // If set, 'wrap' text at right and optionally bottom edge - // of display - bool _swapBytes; // Swap the byte order for TFT pushImage() + textwrapY; // If set, 'wrap' text at right and optionally bottom edge + // of display + bool _swapBytes; // Swap the byte order for TFT pushImage() bool locked, inTransaction; // Transaction and mutex lock flags for ESP32 bool _booted; // init() or begin() has already run once bool _cp437; // If set, use correct CP437 charset (default is ON) - bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function - // (default ON) + bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function + // (default ON) uint32_t _lastColor; // Buffered value of last colour used @@ -977,7 +1021,7 @@ class TFT_eSPI : public Print { // This is part of the TFT_eSPI class and is associated with anti-aliased // font functions -public: + public: // These are for the new antialiased fonts void loadFont(String fontName, fs::FS &ffs); void loadFont(String fontName, bool flash = true); @@ -997,8 +1041,8 @@ class TFT_eSPI : public Print { uint16_t spaceWidth; // Width of a space character int16_t ascent; // Height of top of 'd' above baseline, other // characters may be taller - int16_t descent; // Offset to bottom of 'p', other characters may have - // a larger descent + int16_t descent; // Offset to bottom of 'p', other characters may have + // a larger descent uint16_t maxAscent; // Maximum ascent found in font uint16_t maxDescent; // Maximum descent found in font } fontMetrics; @@ -1019,7 +1063,7 @@ class TFT_eSPI : public Print { bool fontLoaded = false; // Flags when a anti-aliased font is loaded fs::File fontFile; -private: + private: void loadMetrics(uint16_t gCount); uint32_t readInt32(void); diff --git a/src/utility/Sprite.cpp b/src/utility/Sprite.cpp index 74c95e5..54e403d 100644 --- a/src/utility/Sprite.cpp +++ b/src/utility/Sprite.cpp @@ -2241,7 +2241,7 @@ typedef struct { uint16_t outHeight; } jpg_file_decoder_t; -static uint32_t jpgReadFile(JDEC *decoder, uint8_t *buf, uint32_t len) { +static UINT jpgReadFile(JDEC *decoder, uint8_t *buf, UINT len) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; File *file = (File *)jpeg->src; if (buf) { @@ -2252,7 +2252,7 @@ static uint32_t jpgReadFile(JDEC *decoder, uint8_t *buf, uint32_t len) { return len; } -static uint32_t jpgRead(JDEC *decoder, uint8_t *buf, uint32_t len) { +static UINT jpgRead(JDEC *decoder, uint8_t *buf, UINT len) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; if (buf) { memcpy(buf, (const uint8_t *)jpeg->src + jpeg->index, len); @@ -2261,7 +2261,7 @@ static uint32_t jpgRead(JDEC *decoder, uint8_t *buf, uint32_t len) { return len; } -static uint32_t jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { +static UINT jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { jpg_file_decoder_t *jpeg = (jpg_file_decoder_t *)decoder->device; uint16_t x = rect->left; uint16_t y = rect->top; @@ -2335,7 +2335,7 @@ static uint32_t jpgWrite(JDEC *decoder, void *bitmap, JRECT *rect) { } static bool jpgDecode(jpg_file_decoder_t *jpeg, - uint32_t (*reader)(JDEC *, uint8_t *, uint32_t)) { + UINT (*reader)(JDEC *, uint8_t *, UINT)) { static uint8_t work[3100]; JDEC decoder; diff --git a/src/utility/pngle.c b/src/utility/pngle.c index 6b91aa5..528644b 100644 --- a/src/utility/pngle.c +++ b/src/utility/pngle.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include "pngle.h" #ifndef MIN