1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 00:35:39 +03:00

More conversions

This commit is contained in:
jflyper 2017-07-15 01:59:09 +09:00
parent 9233b9fbfd
commit 3f885ce944

View file

@ -186,8 +186,9 @@ static bool i2c_OLED_send_cmd(busDevice_t *bus, uint8_t command)
static bool i2c_OLED_send_cmdarray(busDevice_t *bus, const uint8_t *commands, size_t len)
{
for (size_t i = 0 ; i < len ; i++) {
if (i2c_OLED_send_cmd(bus, *commands++)) {
return false;
if (i2c_OLED_send_cmd(bus, commands[i])) {
// XXX Funny, i2cWrite is returning errors!?
// return;
}
}
@ -199,43 +200,15 @@ static bool i2c_OLED_send_byte(busDevice_t *bus, uint8_t val)
return i2cWrite(bus->busdev_u.i2c.device, bus->busdev_u.i2c.address, 0x40, val);
}
static const uint8_t i2c_OLED_cmd_clear_display_pre[] = {
0xa6, // Set Normal Display
0xae, // Display OFF
0x20, // Set Memory Addressing Mode
0x00, // Set Memory Addressing Mode to Horizontal addressing mode
0xb0, // set page address to 0
0x40, // Display start line register to 0
0, // Set low col address to 0
0x10, // Set high col address to 0
};
static const uint8_t i2c_OLED_cmd_clear_display_post[] = {
0x81, // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction
200, // Here you can set the brightness 1 = dull, 255 is very bright
0xaf, // display on
};
void i2c_OLED_clear_display(busDevice_t *bus)
{
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_clear_display_pre, ARRAYLEN(i2c_OLED_cmd_clear_display_pre));
for (uint16_t i = 0; i < 1024; i++) { // fill the display's RAM with graphic... 128*64 pixel picture
i2c_OLED_send_byte(bus, 0x00); // clear
}
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_clear_display_post, ARRAYLEN(i2c_OLED_cmd_clear_display_post));
}
static const uint8_t i2c_OLED_cmd_clear_display_quick[] = {
0xb0, // set page address to 0
0x40, // Display start line register to 0
0, // Set low col address to 0
0x10, // Set high col address to 0
};
void i2c_OLED_clear_display_quick(busDevice_t *bus)
{
static const uint8_t i2c_OLED_cmd_clear_display_quick[] = {
0xb0, // set page address to 0
0x40, // Display start line register to 0
0, // Set low col address to 0
0x10, // Set high col address to 0
};
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_clear_display_quick, ARRAYLEN(i2c_OLED_cmd_clear_display_quick));
for (uint16_t i = 0; i < 1024; i++) { // fill the display's RAM with graphic... 128*64 pixel picture
@ -243,18 +216,42 @@ void i2c_OLED_clear_display_quick(busDevice_t *bus)
}
}
void i2c_OLED_clear_display(busDevice_t *bus)
{
static const uint8_t i2c_OLED_cmd_clear_display_pre[] = {
0xa6, // Set Normal Display
0xae, // Display OFF
0x20, // Set Memory Addressing Mode
0x00, // Set Memory Addressing Mode to Horizontal addressing mode
};
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_clear_display_pre, ARRAYLEN(i2c_OLED_cmd_clear_display_pre));
i2c_OLED_clear_display_quick(bus);
static const uint8_t i2c_OLED_cmd_clear_display_post[] = {
0x81, // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction
200, // Here you can set the brightness 1 = dull, 255 is very bright
0xaf, // display on
};
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_clear_display_post, ARRAYLEN(i2c_OLED_cmd_clear_display_post));
}
void i2c_OLED_set_xy(busDevice_t *bus, uint8_t col, uint8_t row)
{
i2c_OLED_send_cmd(bus, 0xb0 + row); //set page address
i2c_OLED_send_cmd(bus, 0x00 + ((CHARACTER_WIDTH_TOTAL * col) & 0x0f)); //set low col address
i2c_OLED_send_cmd(bus, 0x10 + (((CHARACTER_WIDTH_TOTAL * col) >> 4) & 0x0f)); //set high col address
uint8_t i2c_OLED_cmd_set_xy[] = {
0xb0 + row, //set page address
0x00 + ((CHARACTER_WIDTH_TOTAL * col) & 0x0f), //set low col address
0x10 + (((CHARACTER_WIDTH_TOTAL * col) >> 4) & 0x0f) //set high col address
};
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_set_xy, ARRAYLEN(i2c_OLED_cmd_set_xy));
}
void i2c_OLED_set_line(busDevice_t *bus, uint8_t row)
{
i2c_OLED_send_cmd(bus, 0xb0 + row); //set page address
i2c_OLED_send_cmd(bus, 0); //set low col address
i2c_OLED_send_cmd(bus, 0x10); //set high col address
i2c_OLED_set_xy(bus, 0, row);
}
void i2c_OLED_send_char(busDevice_t *bus, unsigned char ascii)
@ -282,7 +279,15 @@ void i2c_OLED_send_string(busDevice_t *bus, const char *string)
* according to http://www.adafruit.com/datasheets/UG-2864HSWEG01.pdf Chapter 4.4 Page 15
*/
static const uint8_t i2c_OLED_cmd_init[] = {
bool ug2864hsweg01InitI2C(busDevice_t *bus)
{
// Set display OFF
if (!i2c_OLED_send_cmd(bus, 0xAE)) {
return false;
}
static const uint8_t i2c_OLED_cmd_init[] = {
0xD4, // Set Display Clock Divide Ratio / OSC Frequency
0x80, // Display Clock Divide Ratio / OSC Frequency
0xA8, // Set Multiplex Ratio
@ -305,15 +310,7 @@ static const uint8_t i2c_OLED_cmd_init[] = {
0xA4, // Set all pixels OFF
0xA6, // Set display not inverted
0xAF, // Set display On
};
bool ug2864hsweg01InitI2C(busDevice_t *bus)
{
// Set display OFF
if (!i2c_OLED_send_cmd(bus, 0xAE)) {
return false;
}
};
i2c_OLED_send_cmdarray(bus, i2c_OLED_cmd_init, ARRAYLEN(i2c_OLED_cmd_init));