S60 Support (#1692)
* Mock S60 * cleanup * Start refactor of OLED init * Setup timers roughly * Set Vector table offset correctly Update system_stm32f1xx.c * Update OLED.cpp * Update stm32f1xx_hal_msp.c * Update configuration.h * I2C init before GPIO From Errata Update stm32f1xx_hal_msp.c Update Software_I2C.h Allow no hardware I2C * I2C BB run bus unlock at init * cleanups * Software I2C for now * Mildly more graceful Interpolate * Handle is powered by DC Update Power.cpp Update drawPowerSourceIcon.cpp Update configuration.h Update Setup.cpp * Cleanup HomeScreen * Segment remap oled at init * Cleanup * Update MOVThread.cpp * Fix PWM Init * Fix adc2 trigger * Update configs * Fixup warning * Saner default config * Update ThermoModel.cpp * Util for current@voltage * Hub238 warning * Add hub238 handling in power mode * Update USBPDDebug_FUSB.cpp * HUSB238 debug * Hook PSU Limit * Use wrapping section of GRAM for scroll Update OLED.hpp * Update NTC table * Fix HUB voltage picker * Cleanup * Larger tip filter * Calibrate in a bunch closer Update ThermoModel.cpp * Update configuration.h * Update HUB238.cpp * Update configuration.h * Movement Pin * Update BSP.cpp * tim2 irq * Rough timer conversion (adc broken) but movement working * Fix tim2 start * Faster base PWM * Ensure utils grabs config * Add wattage limiter tolerance for device * Speed up PWM and enable PWM current limiting * tune for 12v * Prevent start until PD done * Update configuration.h * Add HUB238 check for have re-negotiated * Adjust timer to avoid noise when its possible
This commit is contained in:
@@ -23,7 +23,7 @@ OLED::DisplayState OLED::displayState;
|
||||
int16_t OLED::cursor_x, OLED::cursor_y;
|
||||
bool OLED::initDone = false;
|
||||
uint8_t OLED::displayOffset;
|
||||
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
||||
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * (OLED_HEIGHT / 8)) + 10]; // The data buffer
|
||||
uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2];
|
||||
uint32_t OLED::displayChecksum;
|
||||
/*Setup params for the OLED screen*/
|
||||
@@ -32,31 +32,35 @@ uint32_t OLED::displayChecksum;
|
||||
/*Data packets are prefixed with 0x40*/
|
||||
I2C_CLASS::I2C_REG OLED_Setup_Array[] = {
|
||||
/**/
|
||||
{0x80, 0xAE, 0}, /*Display off*/
|
||||
{0x80, 0xD5, 0}, /*Set display clock divide ratio / osc freq*/
|
||||
{0x80, 0x52, 0}, /*Divide ratios*/
|
||||
{0x80, 0xA8, 0}, /*Set Multiplex Ratio*/
|
||||
{0x80, 0x0F, 0}, /*16 == max brightness,39==dimmest*/
|
||||
{0x80, 0xC0, 0}, /*Set COM Scan direction*/
|
||||
{0x80, 0xD3, 0}, /*Set vertical Display offset*/
|
||||
{0x80, 0x00, 0}, /*0 Offset*/
|
||||
{0x80, 0x40, 0}, /*Set Display start line to 0*/
|
||||
{0x80, 0xA0, 0}, /*Set Segment remap to normal*/
|
||||
{0x80, 0x8D, 0}, /*Charge Pump*/
|
||||
{0x80, 0x14, 0}, /*Charge Pump settings*/
|
||||
{0x80, 0xDA, 0}, /*Set VCOM Pins hardware config*/
|
||||
{0x80, 0x02, 0}, /*Combination 2*/
|
||||
{0x80, 0x81, 0}, /*Brightness*/
|
||||
{0x80, 0x00, 0}, /*^0*/
|
||||
{0x80, 0xD9, 0}, /*Set pre-charge period*/
|
||||
{0x80, 0xF1, 0}, /*Pre charge period*/
|
||||
{0x80, 0xDB, 0}, /*Adjust VCOMH regulator ouput*/
|
||||
{0x80, 0x30, 0}, /*VCOM level*/
|
||||
{0x80, 0xA4, 0}, /*Enable the display GDDR*/
|
||||
{0x80, 0XA6, 0}, /*Normal display*/
|
||||
{0x80, 0x20, 0}, /*Memory Mode*/
|
||||
{0x80, 0x00, 0}, /*Wrap memory*/
|
||||
{0x80, 0xAF, 0}, /*Display on*/
|
||||
{0x80, 0xAE, 0}, /*Display off*/
|
||||
{0x80, 0xD5, 0}, /*Set display clock divide ratio / osc freq*/
|
||||
{0x80, 0x52, 0}, /*Divide ratios*/
|
||||
{0x80, 0xA8, 0}, /*Set Multiplex Ratio*/
|
||||
{0x80, OLED_HEIGHT - 1, 0}, /*Multiplex ratio adjusts how far down the matrix it scans*/
|
||||
{0x80, 0xC0, 0}, /*Set COM Scan direction*/
|
||||
{0x80, 0xD3, 0}, /*Set vertical Display offset*/
|
||||
{0x80, 0x00, 0}, /*0 Offset*/
|
||||
{0x80, 0x40, 0}, /*Set Display start line to 0*/
|
||||
#ifdef OLED_SEGMENT_MAP_REVERSED
|
||||
{0x80, 0xA1, 0}, /*Set Segment remap to normal*/
|
||||
#else
|
||||
{0x80, 0xA0, 0}, /*Set Segment remap to normal*/
|
||||
#endif
|
||||
{0x80, 0x8D, 0}, /*Charge Pump*/
|
||||
{0x80, 0x14, 0}, /*Charge Pump settings*/
|
||||
{0x80, 0xDA, 0}, /*Set VCOM Pins hardware config*/
|
||||
{0x80, OLED_VCOM_LAYOUT, 0}, /*Combination 0x2 or 0x12 depending on OLED model*/
|
||||
{0x80, 0x81, 0}, /*Brightness*/
|
||||
{0x80, 0x00, 0}, /*^0*/
|
||||
{0x80, 0xD9, 0}, /*Set pre-charge period*/
|
||||
{0x80, 0xF1, 0}, /*Pre charge period*/
|
||||
{0x80, 0xDB, 0}, /*Adjust VCOMH regulator ouput*/
|
||||
{0x80, 0x30, 0}, /*VCOM level*/
|
||||
{0x80, 0xA4, 0}, /*Enable the display GDDR*/
|
||||
{0x80, 0XA6, 0}, /*Normal display*/
|
||||
{0x80, 0x20, 0}, /*Memory Mode*/
|
||||
{0x80, 0x00, 0}, /*Wrap memory*/
|
||||
{0x80, 0xAF, 0}, /*Display on*/
|
||||
};
|
||||
// Setup based on the SSD1307 and modified for the SSD1306
|
||||
|
||||
@@ -71,9 +75,9 @@ const uint8_t REFRESH_COMMANDS[17] = {
|
||||
0x80,
|
||||
0x21, // cmd
|
||||
0x80,
|
||||
0x20, // A
|
||||
OLED_GRAM_START, // A
|
||||
0x80,
|
||||
0x7F, // B
|
||||
OLED_GRAM_END, // B
|
||||
|
||||
// Set COM output scan direction (normal mode, COM0 to COM[N-1])
|
||||
0x80,
|
||||
@@ -87,7 +91,7 @@ const uint8_t REFRESH_COMMANDS[17] = {
|
||||
0x80,
|
||||
0x00, // A
|
||||
0x80,
|
||||
0x01, // B
|
||||
(OLED_HEIGHT / 8), // B
|
||||
|
||||
// Start of data
|
||||
0x40,
|
||||
@@ -217,7 +221,7 @@ void OLED::maskScrollIndicatorOnOLED() {
|
||||
// it from the screen buffer which is updated by `OLED::setRotation`.
|
||||
uint8_t rightmostColumn = screenBuffer[7];
|
||||
uint8_t maskCommands[] = {
|
||||
// Set column address:
|
||||
// Set column address:
|
||||
// A[6:0] - Column start address = rightmost column
|
||||
// B[6:0] - Column end address = rightmost column
|
||||
0x80,
|
||||
@@ -304,24 +308,26 @@ void OLED::useSecondaryFramebuffer(bool useSecondary) {
|
||||
* method, as doing so will overwrite the previous screen data. The caller
|
||||
* does not need to call `OLED::refresh()` after this function returns.
|
||||
*
|
||||
* **This function blocks until the transition has completed.**
|
||||
* **This function blocks until the transition has completed or user presses button**
|
||||
*/
|
||||
void OLED::transitionScrollDown() {
|
||||
// We want to draw the updated framebuffer to the next page downward.
|
||||
uint8_t const pageStart = screenBuffer[13];
|
||||
uint8_t const nextPage = (pageStart + 2) % 8;
|
||||
uint8_t const nextPage = (pageStart + (OLED_HEIGHT / 8)) % 8;
|
||||
// Change page start address:
|
||||
screenBuffer[13] = nextPage;
|
||||
// Change page end address:
|
||||
screenBuffer[15] = nextPage + 1;
|
||||
screenBuffer[15] = (nextPage + 1) % 8;
|
||||
|
||||
refresh();
|
||||
refresh(); // Now refresh to write out the contents to the new page
|
||||
osDelay(TICKS_100MS / 5);
|
||||
|
||||
uint8_t const startLine = pageStart * 8 + 1;
|
||||
uint8_t const scrollTo = (pageStart + 2) * 8;
|
||||
uint8_t startLine = (pageStart * 8) + 1;
|
||||
|
||||
uint8_t scrollTo = (pageStart + (OLED_HEIGHT / 8)) * 8;
|
||||
|
||||
// Scroll the screen by changing display start line.
|
||||
// This effectively scrolls off the bottom of the current page and into the next one
|
||||
for (uint8_t current = startLine; current <= scrollTo; current++) {
|
||||
if (getButtonState() != BUTTON_NONE) {
|
||||
current = scrollTo;
|
||||
@@ -337,6 +343,13 @@ void OLED::transitionScrollDown() {
|
||||
I2C_CLASS::I2C_RegisterWrite(DEVICEADDR_OLED, 0x80, scrollCommandByte);
|
||||
osDelay(TICKS_100MS / 7);
|
||||
}
|
||||
// Now that scroll is done, revert to default page to avoid wrap issues
|
||||
screenBuffer[13] = pageStart;
|
||||
screenBuffer[15] = (pageStart + 1) % 8;
|
||||
uint8_t scrollCommandByte = 0b01000000;
|
||||
OLED_Setup_Array[8].val = scrollCommandByte;
|
||||
I2C_CLASS::I2C_RegisterWrite(DEVICEADDR_OLED, 0x80, scrollCommandByte);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void OLED::setRotation(bool leftHanded) {
|
||||
@@ -346,22 +359,32 @@ void OLED::setRotation(bool leftHanded) {
|
||||
if (inLeftHandedMode == leftHanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef OLED_SEGMENT_MAP_REVERSED
|
||||
if (!leftHanded) {
|
||||
OLED_Setup_Array[9].val = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[9].val = 0xA0;
|
||||
}
|
||||
#else
|
||||
if (leftHanded) {
|
||||
OLED_Setup_Array[9].val = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[9].val = 0xA0;
|
||||
}
|
||||
#endif
|
||||
// send command struct again with changes
|
||||
if (leftHanded) {
|
||||
OLED_Setup_Array[5].val = 0xC8; // c1?
|
||||
OLED_Setup_Array[9].val = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[5].val = 0xC0;
|
||||
OLED_Setup_Array[9].val = 0xA0;
|
||||
}
|
||||
I2C_CLASS::writeRegistersBulk(DEVICEADDR_OLED, OLED_Setup_Array, sizeof(OLED_Setup_Array) / sizeof(OLED_Setup_Array[0]));
|
||||
osDelay(TICKS_10MS);
|
||||
inLeftHandedMode = leftHanded;
|
||||
|
||||
screenBuffer[5] = inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed
|
||||
// mode as driver ram is 128 wide
|
||||
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; // End address of the ram segment we are writing to (96 wide)
|
||||
screenBuffer[5] = inLeftHandedMode ? OLED_GRAM_START_FLIP : OLED_GRAM_START; // display is shifted by 32 in left handed
|
||||
// mode as driver ram is 128 wide
|
||||
screenBuffer[7] = inLeftHandedMode ? OLED_GRAM_END_FLIP : OLED_GRAM_END; // End address of the ram segment we are writing to (96 wide)
|
||||
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
|
||||
// Force a screen refresh
|
||||
const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2);
|
||||
|
||||
Reference in New Issue
Block a user