ssd1306 code cleanup
Added U(202) HARD reset - reboots pi
This commit is contained in:
parent
02f19df0cf
commit
0bcd9de494
4 changed files with 40 additions and 60 deletions
|
@ -35,7 +35,6 @@ extern "C"
|
||||||
#define PNG_WIDTH 320
|
#define PNG_WIDTH 320
|
||||||
#define PNG_HEIGHT 200
|
#define PNG_HEIGHT 200
|
||||||
|
|
||||||
|
|
||||||
unsigned char FileBrowser::LSTBuffer[FileBrowser::LSTBuffer_size];
|
unsigned char FileBrowser::LSTBuffer[FileBrowser::LSTBuffer_size];
|
||||||
|
|
||||||
const unsigned FileBrowser::SwapKeys[30] =
|
const unsigned FileBrowser::SwapKeys[30] =
|
||||||
|
|
|
@ -25,46 +25,21 @@ extern "C"
|
||||||
#include "xga_font_data.h"
|
#include "xga_font_data.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE 0x20
|
|
||||||
|
|
||||||
#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21
|
|
||||||
#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22
|
|
||||||
#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E
|
|
||||||
#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F
|
|
||||||
|
|
||||||
#define SSD1306_CMD_SET_CONTRAST_CONTROL 0x81 // Set Contrast Control for BANK0
|
|
||||||
#define SSD1306_ENABLE_CHARGE_PUMP 0x8D
|
|
||||||
|
|
||||||
#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA4
|
|
||||||
#define SSD1306_CMD_ENTIRE_DISPLAY_OFF 0xA5
|
|
||||||
#define SSD1306_CMD_NORMAL_DISPLAY 0xA6 // 1 = on pixel
|
|
||||||
#define SSD1306_CMD_INVERT_DISPLAY 0xA7 // 0 = on pixel
|
|
||||||
|
|
||||||
#define SSD1306_CMD_DISPLAY_OFF 0xAE
|
|
||||||
#define SSD1306_CMD_DISPLAY_ON 0xAF
|
|
||||||
#define SSD1306_CMD_MULTIPLEX_RATIO 0xA8
|
|
||||||
|
|
||||||
#define SSD1306_CMD_SET_START_LINE 0x40
|
|
||||||
|
|
||||||
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3
|
|
||||||
#define SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO 0xD5
|
|
||||||
#define SSD1306_CMD_SET_PRE_CHARGE_PERIOD 0xD9
|
|
||||||
#define SSD1306_CMD_SET_COM_PINS 0xDA
|
|
||||||
#define SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL 0xDB
|
|
||||||
|
|
||||||
#define SSD1306_CONTROL_REG 0x00
|
|
||||||
#define SSD1306_DATA_REG 0x40
|
|
||||||
|
|
||||||
unsigned char frame[SSD1306_128x64_BYTES];
|
unsigned char frame[SSD1306_128x64_BYTES];
|
||||||
|
|
||||||
SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type)
|
SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type)
|
||||||
: BSCMaster(BSCMaster)
|
: BSCMaster(BSCMaster)
|
||||||
, address(address)
|
, address(address)
|
||||||
, type(type)
|
, type(type)
|
||||||
|
, flip(flip)
|
||||||
{
|
{
|
||||||
RPI_I2CInit(BSCMaster, 1);
|
RPI_I2CInit(BSCMaster, 1);
|
||||||
|
|
||||||
|
SetupScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSD1306::SetupScreen()
|
||||||
|
{
|
||||||
// SSD1306 data sheet configuration flow
|
// SSD1306 data sheet configuration flow
|
||||||
SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE
|
SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE
|
||||||
SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8
|
SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8
|
||||||
|
@ -93,9 +68,6 @@ SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type)
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_NORMAL_DISPLAY); // 0xA6 = non inverted
|
SendCommand(SSD1306_CMD_NORMAL_DISPLAY); // 0xA6 = non inverted
|
||||||
|
|
||||||
// SendCommand(0xD5); // CLOCK_DIVIDER_FREQ
|
|
||||||
// SendCommand(0x80); // 7:4 oscillator f, 3:0 divider
|
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_SET_PRE_CHARGE_PERIOD); // 0xD9
|
SendCommand(SSD1306_CMD_SET_PRE_CHARGE_PERIOD); // 0xD9
|
||||||
SendCommand(0xF1);
|
SendCommand(0xF1);
|
||||||
|
|
||||||
|
@ -108,27 +80,11 @@ SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type)
|
||||||
SendCommand(SSD1306_ENABLE_CHARGE_PUMP); // Enable charge pump regulator
|
SendCommand(SSD1306_ENABLE_CHARGE_PUMP); // Enable charge pump regulator
|
||||||
SendCommand(0x14); // external = 0x10 internal = 0x14
|
SendCommand(0x14); // external = 0x10 internal = 0x14
|
||||||
|
|
||||||
/* only for page mode addressing? so can be deleted
|
|
||||||
SendCommand(0x00); // Set Lower Column Start Address
|
|
||||||
SendCommand(0x10); // Set Higher Column Start Address
|
|
||||||
SendCommand(0xB0); // Set Page Start Address for Page Addressing Mode
|
|
||||||
*/
|
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE); // Set Memory Addressing Mode
|
SendCommand(SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE); // Set Memory Addressing Mode
|
||||||
SendCommand(0x00); // 00 - Horizontal Addressing Mode
|
SendCommand(0x00); // 00 - Horizontal Addressing Mode
|
||||||
|
|
||||||
Home();
|
Home();
|
||||||
|
|
||||||
/* replaced by Home
|
|
||||||
SendCommand(SSD1306_CMD_SET_COLUMN_ADDRESS); // 0x21 Set Column Address (only for horizontal or vertical mode)
|
|
||||||
SendCommand(0x00); // start 0
|
|
||||||
SendCommand(0x7F); // end 127
|
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_SET_PAGE_ADDRESS); // 0x22
|
|
||||||
SendCommand(0x00); // start 0
|
|
||||||
SendCommand(0x07); // end 7 (so 8 vertical bytes == 64 row display)
|
|
||||||
*/
|
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_DEACTIVATE_SCROLL);
|
SendCommand(SSD1306_CMD_DEACTIVATE_SCROLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,14 +122,6 @@ void SSD1306::MoveCursorByte(u8 row, u8 col)
|
||||||
SetDisplayWindow(col+2, 129, row, 7); // sh1106 has 132x64 ram, display is centreed
|
SetDisplayWindow(col+2, 129, row, 7); // sh1106 has 132x64 ram, display is centreed
|
||||||
else
|
else
|
||||||
SetDisplayWindow(col+0, 127, row, 7);
|
SetDisplayWindow(col+0, 127, row, 7);
|
||||||
/*
|
|
||||||
SendCommand(0x21); // set column
|
|
||||||
SendCommand(col); // start = col
|
|
||||||
SendCommand(0x7F); // end = col max
|
|
||||||
SendCommand(0x22); // set row
|
|
||||||
SendCommand(row); // start = row
|
|
||||||
SendCommand(0x07); // end = row max
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSD1306::MoveCursorCharacter(u8 row, u8 col)
|
void SSD1306::MoveCursorCharacter(u8 row, u8 col)
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
void PlotCharacter(int x, int y, char ascii, bool inverse);
|
void PlotCharacter(int x, int y, char ascii, bool inverse);
|
||||||
void Plottext(int x, int y, char* str, bool inverse);
|
void Plottext(int x, int y, char* str, bool inverse);
|
||||||
|
|
||||||
|
void SetupScreen();
|
||||||
void DisplayOn();
|
void DisplayOn();
|
||||||
void DisplayOff();
|
void DisplayOff();
|
||||||
void SetContrast(u8 value);
|
void SetContrast(u8 value);
|
||||||
|
@ -106,5 +107,30 @@ protected:
|
||||||
int BSCMaster;
|
int BSCMaster;
|
||||||
u8 address;
|
u8 address;
|
||||||
int type;
|
int type;
|
||||||
|
int flip;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define SSD1306_CMD_SET_MEMORY_ADDRESSING_MODE 0x20
|
||||||
|
#define SSD1306_CMD_SET_COLUMN_ADDRESS 0x21
|
||||||
|
#define SSD1306_CMD_SET_PAGE_ADDRESS 0x22
|
||||||
|
#define SSD1306_CMD_DEACTIVATE_SCROLL 0x2E
|
||||||
|
#define SSD1306_CMD_ACTIVATE_SCROLL 0x2F
|
||||||
|
#define SSD1306_CMD_SET_CONTRAST_CONTROL 0x81 // Set Contrast Control for BANK0
|
||||||
|
#define SSD1306_ENABLE_CHARGE_PUMP 0x8D
|
||||||
|
#define SSD1306_CMD_ENTIRE_DISPLAY_ON 0xA4
|
||||||
|
#define SSD1306_CMD_ENTIRE_DISPLAY_OFF 0xA5
|
||||||
|
#define SSD1306_CMD_NORMAL_DISPLAY 0xA6 // 1 = on pixel
|
||||||
|
#define SSD1306_CMD_INVERT_DISPLAY 0xA7 // 0 = on pixel
|
||||||
|
#define SSD1306_CMD_DISPLAY_OFF 0xAE
|
||||||
|
#define SSD1306_CMD_DISPLAY_ON 0xAF
|
||||||
|
#define SSD1306_CMD_MULTIPLEX_RATIO 0xA8
|
||||||
|
#define SSD1306_CMD_SET_START_LINE 0x40
|
||||||
|
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3
|
||||||
|
#define SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO 0xD5
|
||||||
|
#define SSD1306_CMD_SET_PRE_CHARGE_PERIOD 0xD9
|
||||||
|
#define SSD1306_CMD_SET_COM_PINS 0xDA
|
||||||
|
#define SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL 0xDB
|
||||||
|
#define SSD1306_CONTROL_REG 0x00
|
||||||
|
#define SSD1306_DATA_REG 0x40
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
extern unsigned versionMajor;
|
extern unsigned versionMajor;
|
||||||
extern unsigned versionMinor;
|
extern unsigned versionMinor;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
extern void reboot_now(void);
|
||||||
|
}
|
||||||
|
|
||||||
#define WaitWhile(checkStatus) \
|
#define WaitWhile(checkStatus) \
|
||||||
do\
|
do\
|
||||||
{\
|
{\
|
||||||
|
@ -1278,10 +1282,13 @@ void IEC_Commands::User(void)
|
||||||
|
|
||||||
case 'J':
|
case 'J':
|
||||||
case ':':
|
case ':':
|
||||||
case 202:
|
|
||||||
// Hard reset
|
// Hard reset
|
||||||
Error(ERROR_73_DOSVERSION);
|
Error(ERROR_73_DOSVERSION);
|
||||||
break;
|
break;
|
||||||
|
case 202:
|
||||||
|
// Really hard reset - reboot Pi
|
||||||
|
reboot_now();
|
||||||
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
//OPEN1,8,15,"U0>"+CHR$(9):CLOSE1
|
//OPEN1,8,15,"U0>"+CHR$(9):CLOSE1
|
||||||
if ((channel.buffer[2] & 0x1f) == 0x1e && channel.buffer[3] >= 4 && channel.buffer[3] <= 30)
|
if ((channel.buffer[2] & 0x1f) == 0x1e && channel.buffer[3] >= 4 && channel.buffer[3] <= 30)
|
||||||
|
|
Loading…
Reference in a new issue