mirror of
https://github.com/Matiasus/SSD1306.git
synced 2024-09-19 17:45:59 -04:00
Draw line horizontal from x1 to x2
This commit is contained in:
parent
85cb65f165
commit
8580ddc78c
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
* @author Marian Hrinko
|
* @author Marian Hrinko
|
||||||
* @datum 06.10.2020
|
* @datum 06.10.2020
|
||||||
* @update 24.11.2022
|
* @update 06.12.2022
|
||||||
* @file ssd1306.c
|
* @file ssd1306.c
|
||||||
* @version 3.0
|
* @version 3.0
|
||||||
* @tested AVR Atmega328p
|
* @tested AVR Atmega328p
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* --------------------------------------------------------------------------------------+
|
* --------------------------------------------------------------------------------------+
|
||||||
* @usage Basic Setup for OLED Display
|
* @usage Basic Setup for OLED Display
|
||||||
*/
|
*/
|
||||||
|
// @includes
|
||||||
#include "ssd1306.h"
|
#include "ssd1306.h"
|
||||||
|
|
||||||
// +---------------------------+
|
// +---------------------------+
|
||||||
@ -597,22 +597,32 @@ uint8_t SSD1306_DrawPixel (uint8_t x, uint8_t y)
|
|||||||
uint8_t SSD1306_DrawLineHorz (uint8_t y, uint8_t x1, uint8_t x2)
|
uint8_t SSD1306_DrawLineHorz (uint8_t y, uint8_t x1, uint8_t x2)
|
||||||
{
|
{
|
||||||
uint8_t status = INIT_STATUS; // TWI init status 0xFF
|
uint8_t status = INIT_STATUS; // TWI init status 0xFF
|
||||||
uint8_t i = 0; // counter
|
uint8_t i = 0; // counter for y dim
|
||||||
uint8_t j = 0; // counter
|
uint8_t j = 0; // counter for x dim
|
||||||
uint8_t page = y >> 3; // page
|
uint8_t page = y >> 3; // page
|
||||||
uint8_t pixel = 1 << (y - (page << 3)); // pixel
|
uint8_t pixel = 1 << (y - (page << 3)); // which pixel
|
||||||
|
uint8_t ram[RAM_Y_END][RAM_X_END]; // buffer [3/7 x 127]
|
||||||
|
|
||||||
uint8_t ram[RAM_Y_END][RAM_X_END];
|
// fill RAM buffer
|
||||||
|
// -------------------------------------------------------------------------------------
|
||||||
while (i < RAM_Y_END) {
|
while (i < RAM_Y_END)
|
||||||
if (i == page) {
|
{
|
||||||
memset (ram[i], pixel, RAM_X_END);
|
if (i == page) { // for correspond page
|
||||||
} else {
|
//memset (ram[i], pixel, RAM_X_END); // draw line
|
||||||
memset (ram[i], 0x00, RAM_X_END);
|
while (j < x1) { //
|
||||||
|
ram[i][j++] = CLEAR_COLOR; // clear to x1
|
||||||
}
|
}
|
||||||
i++;
|
while (j < x2) { //
|
||||||
|
ram[i][j++] = pixel; // set pixels to x2
|
||||||
|
}
|
||||||
|
while (j < RAM_X_END) { //
|
||||||
|
ram[i][j++] = CLEAR_COLOR; // clear to x end
|
||||||
|
}
|
||||||
|
} else { //
|
||||||
|
memset (ram[i], CLEAR_COLOR, RAM_X_END); // clear whole page
|
||||||
|
}
|
||||||
|
i++; // next page
|
||||||
}
|
}
|
||||||
|
|
||||||
// TWI start & SLAW
|
// TWI start & SLAW
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
status = SSD1306_Send_StartAndSLAW (SSD1306_ADDR); // start & SLAW
|
status = SSD1306_Send_StartAndSLAW (SSD1306_ADDR); // start & SLAW
|
||||||
@ -626,16 +636,15 @@ uint8_t SSD1306_DrawLineHorz (uint8_t y, uint8_t x1, uint8_t x2)
|
|||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
// start COLUMN
|
// start COLUMN
|
||||||
status = SSD1306_Send_Command (0);
|
status = SSD1306_Send_Command (START_COLUMN_ADDR);
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
// end COLUMN
|
// end COLUMN
|
||||||
status = SSD1306_Send_Command (127);
|
status = SSD1306_Send_Command (END_COLUMN_ADDR);
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// PAGE
|
// PAGE
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
status = SSD1306_Send_Command (SSD1306_SET_PAGE_ADDR); // 0x22
|
status = SSD1306_Send_Command (SSD1306_SET_PAGE_ADDR); // 0x22
|
||||||
@ -643,62 +652,43 @@ uint8_t SSD1306_DrawLineHorz (uint8_t y, uint8_t x1, uint8_t x2)
|
|||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
// start PAGE
|
// start PAGE
|
||||||
status = SSD1306_Send_Command (0);
|
status = SSD1306_Send_Command (START_PAGE_ADDR);
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
// end PAGE
|
// end PAGE
|
||||||
status = SSD1306_Send_Command (3);
|
status = SSD1306_Send_Command (END_PAGE_ADDR);
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TWI control byte data stream
|
// TWI control byte data stream
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
status = TWI_MT_Send_Data (SSD1306_DATA_STREAM); // send data 0x40
|
status = TWI_MT_Send_Data (SSD1306_DATA_STREAM); // send data 0x40
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
// send pixels
|
// send pixels
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
while (i < RAM_Y_END) {
|
while (i < RAM_Y_END) {
|
||||||
while (j < RAM_X_END) {
|
while (j < RAM_X_END) {
|
||||||
status = TWI_MT_Send_Data (ram[i][j]); // send data col
|
status = TWI_MT_Send_Data (ram[i][j]); // send RAM buffer
|
||||||
if (SSD1306_SUCCESS != status) { // check status
|
if (SSD1306_SUCCESS != status) { // check status
|
||||||
return status; // error
|
return status; // error
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
j = 0;
|
j = 0; // null x counter
|
||||||
i++;
|
i++; // next page
|
||||||
}
|
}
|
||||||
|
|
||||||
// TWI stop
|
// TWI stop
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
TWI_Stop ();
|
TWI_Stop ();
|
||||||
|
|
||||||
|
|
||||||
return SSD1306_SUCCESS; // success return
|
return SSD1306_SUCCESS; // success return
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @desc Draw line vertical
|
|
||||||
*
|
|
||||||
* @param uint8_t
|
|
||||||
* @param uint8_t
|
|
||||||
* @param uint8_t
|
|
||||||
*
|
|
||||||
* @return uint8_t
|
|
||||||
*/
|
|
||||||
uint8_t SSD1306_DrawLineVert (uint8_t x, uint8_t y1, uint8_t y2)
|
|
||||||
{
|
|
||||||
|
|
||||||
return SSD1306_SUCCESS; // success
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Draw line by Bresenham algoritm
|
* @desc Draw line by Bresenham algoritm
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user