adjusted old code to new spi and gpi
minor fixes
This commit is contained in:
@@ -76,8 +76,8 @@
|
||||
|
||||
|
||||
|
||||
#include "../../io/SoftSPI.h"
|
||||
#include "../../io/HardSPI.h"
|
||||
//#include "../../io/SoftSPI.h"
|
||||
//#include "../../io/HardSPI.h"
|
||||
|
||||
|
||||
static constexpr const uint8_t initcmd[] = {
|
||||
@@ -107,7 +107,7 @@ static constexpr const uint8_t initcmd[] = {
|
||||
};
|
||||
|
||||
//template <int PIN_CS, int PIN_MISO, int PIN_MOSI, int PIN_CLK, int PIN_DATA_COMMAND> class ILI9341 {
|
||||
template <int PIN_CS, int PIN_DATA_COMMAND, typename SPI> class ILI9341 {
|
||||
template <typename SPI, int PIN_CS, int PIN_DATA_COMMAND> class ILI9341 {
|
||||
|
||||
private:
|
||||
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
|
||||
ILI9341(SPI& spi) : spi(spi) {
|
||||
|
||||
GPIO::setOutput(PIN_DATA_COMMAND);
|
||||
GPIO::setOutput(PIN_CS);
|
||||
MyGPIO::setOutput(PIN_DATA_COMMAND);
|
||||
MyGPIO::setOutput(PIN_CS);
|
||||
|
||||
//spi.init();
|
||||
|
||||
@@ -296,7 +296,7 @@ private:
|
||||
/** select the display (CS=0) */
|
||||
inline void chipSelect() {
|
||||
//spi::chipSelect();
|
||||
GPIO::clear(PIN_CS);
|
||||
MyGPIO::clear(PIN_CS);
|
||||
}
|
||||
|
||||
|
||||
@@ -344,19 +344,19 @@ private:
|
||||
/** unselect the display (CS=1) */
|
||||
inline void chipDeselect() {
|
||||
//spi::chipDeselect();
|
||||
GPIO::set(PIN_CS);
|
||||
MyGPIO::set(PIN_CS);
|
||||
}
|
||||
|
||||
/** switch to command-mode */
|
||||
inline void modeCMD() {
|
||||
//gpio_set_level((gpio_num_t)PIN_DATA_COMMAND, 0);
|
||||
GPIO::clear(PIN_DATA_COMMAND);
|
||||
MyGPIO::clear(PIN_DATA_COMMAND);
|
||||
}
|
||||
|
||||
/** switch to data-mode */
|
||||
inline void modeDATA() {
|
||||
//gpio_set_level((gpio_num_t)PIN_DATA_COMMAND, 1);
|
||||
GPIO::set(PIN_DATA_COMMAND);
|
||||
MyGPIO::set(PIN_DATA_COMMAND);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef LCD_SSD1306
|
||||
#define LCD_SSD1306
|
||||
|
||||
#include "../../io/SoftSPI.h"
|
||||
//#include "../../io/SoftSPI.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -17,46 +17,24 @@
|
||||
* CS = chip-select
|
||||
*/
|
||||
|
||||
class ST7735 {
|
||||
template <typename SPI, int PIN_CS, int PIN_DATA_COMMAND> class ST7735 {
|
||||
|
||||
private:
|
||||
|
||||
static constexpr const char* NAME = "ST7735";
|
||||
|
||||
bool inited = false;
|
||||
|
||||
/** switch D/C line low */
|
||||
inline void modeCommand() {
|
||||
GPIO5_OUTPUT_SET;
|
||||
GPIO5_L;
|
||||
}
|
||||
|
||||
/** switch D/C line high */
|
||||
inline void modeData() {
|
||||
GPIO5_OUTPUT_SET;
|
||||
GPIO5_H;
|
||||
}
|
||||
|
||||
/** set CS = low */
|
||||
inline void select() {
|
||||
spi::chipSelect();
|
||||
}
|
||||
|
||||
/** set CS = high */
|
||||
inline void deselect() {
|
||||
spi::chipDeselect();
|
||||
}
|
||||
|
||||
SPI& spi;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void initOnce() {
|
||||
if (inited) {return;}
|
||||
/** ctor */
|
||||
ST7735(SPI& spi) : spi(spi) {
|
||||
MyGPIO::setOutput(PIN_DATA_COMMAND);
|
||||
MyGPIO::setOutput(PIN_CS);
|
||||
init();
|
||||
inited = true;
|
||||
}
|
||||
|
||||
|
||||
#define ST7735_NOP 0x00
|
||||
#define ST7735_SWRESET 0x01
|
||||
#define ST7735_RDDID 0x04
|
||||
@@ -111,17 +89,19 @@ private:
|
||||
|
||||
void waitLong() {
|
||||
for (int i = 0; i < 50; ++i) {
|
||||
os_delay_us(10*1000);
|
||||
//os_delay_us(10*1000);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void waitShort() {
|
||||
os_delay_us(10*1000);
|
||||
//os_delay_us(10*1000);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
||||
spi::init();
|
||||
//spi::init();
|
||||
|
||||
select();
|
||||
|
||||
@@ -239,7 +219,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
void flush(uint16_t* data) {
|
||||
void flush(const uint16_t* data) {
|
||||
|
||||
select();
|
||||
|
||||
@@ -264,7 +244,8 @@ public:
|
||||
//const uint8_t hi = color >> 8;
|
||||
//sendData(lo);
|
||||
//sendData(hi);
|
||||
spi::writeWord(color);
|
||||
//spi::writeWord(color);
|
||||
spi.writeWord(color);
|
||||
}
|
||||
|
||||
deselect();
|
||||
@@ -278,17 +259,46 @@ private:
|
||||
void sendData(uint8_t data) {
|
||||
modeData();
|
||||
//select();
|
||||
spi::writeByte(data);
|
||||
//spi::writeByte(data);
|
||||
spi.writeByte(data);
|
||||
//deselect();
|
||||
}
|
||||
|
||||
void sendCommand(uint8_t cmd) {
|
||||
modeCommand();
|
||||
//select();
|
||||
spi::writeByte(cmd);
|
||||
//spi::writeByte(cmd);
|
||||
spi.writeByte(cmd);
|
||||
//deselect();
|
||||
}
|
||||
|
||||
/** switch D/C line low */
|
||||
inline void modeCommand() {
|
||||
//GPIO5_OUTPUT_SET;
|
||||
//GPIO5_L;
|
||||
MyGPIO::clear(PIN_DATA_COMMAND);
|
||||
}
|
||||
|
||||
/** switch D/C line high */
|
||||
inline void modeData() {
|
||||
//GPIO5_OUTPUT_SET;
|
||||
//GPIO5_H;
|
||||
MyGPIO::set(PIN_DATA_COMMAND);
|
||||
}
|
||||
|
||||
/** set CS = low */
|
||||
inline void select() {
|
||||
MyGPIO::clear(PIN_CS);
|
||||
//spi::chipSelect();
|
||||
}
|
||||
|
||||
/** set CS = high */
|
||||
inline void deselect() {
|
||||
//spi::chipDeselect();
|
||||
MyGPIO::set(PIN_CS);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -369,12 +369,12 @@ private:
|
||||
/** perform hard reset */
|
||||
void reset() {
|
||||
debugMod(NAME, "reset");
|
||||
//MyGPIO::set(PIN_RESET);
|
||||
//usleep(20*1000);
|
||||
MyGPIO::clear(PIN_RESET); // perform reset
|
||||
usleep(20*1000);
|
||||
MyGPIO::set(PIN_RESET);
|
||||
usleep(20*1000);
|
||||
usleep(50*1000);
|
||||
MyGPIO::clear(PIN_RESET); // perform reset
|
||||
usleep(50*1000);
|
||||
MyGPIO::set(PIN_RESET);
|
||||
usleep(50*1000);
|
||||
debugMod(NAME, "reset done");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user