Code formatting fixed

This commit is contained in:
UncleRus 2016-12-12 00:12:21 +05:00
parent 1a443195fd
commit fa5166a48c
2 changed files with 127 additions and 129 deletions

View file

@ -3,10 +3,11 @@
* *
* Copyright (c) 2016 urx (https://github.com/urx), * Copyright (c) 2016 urx (https://github.com/urx),
* Ruslan V. Uss (https://github.com/UncleRus) * Ruslan V. Uss (https://github.com/UncleRus)
* Zaltora (https://github.com/Zaltora)
* *
* MIT Licensed as described in the file LICENSE * MIT Licensed as described in the file LICENSE
* *
* @todo Scrolling, fonts * @todo HW scrolling, sprites
*/ */
#include "ssd1306.h" #include "ssd1306.h"
#include <stdio.h> #include <stdio.h>
@ -553,7 +554,7 @@ int ssd1306_draw_vline(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y, ui
break; break;
} }
} }
if (t) // // partial line at bottom if (t) // partial line at bottom
{ {
mod = t & 7; mod = t & 7;
static const uint8_t postmask[8] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F }; static const uint8_t postmask[8] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
@ -572,8 +573,6 @@ int ssd1306_draw_vline(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y, ui
default: default:
break; break;
} }
} }
return 0; return 0;
} }
@ -588,7 +587,6 @@ int ssd1306_draw_rectangle(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y
if ((err = ssd1306_draw_vline(dev, fb, x, y, h, color))) if ((err = ssd1306_draw_vline(dev, fb, x, y, h, color)))
return err; return err;
return ssd1306_draw_vline(dev, fb, x + w - 1, y, h, color); return ssd1306_draw_vline(dev, fb, x + w - 1, y, h, color);
} }
@ -606,7 +604,6 @@ int ssd1306_fill_rectangle(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y
int ssd1306_draw_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0, uint8_t r, ssd1306_color_t color) int ssd1306_draw_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0, uint8_t r, ssd1306_color_t color)
{ {
// Refer to http://en.wikipedia.org/wiki/Midpoint_circle_algorithm for the algorithm // Refer to http://en.wikipedia.org/wiki/Midpoint_circle_algorithm for the algorithm
int8_t x = r; int8_t x = r;
int8_t y = 1; int8_t y = 1;
int16_t radius_err = 1 - x; int16_t radius_err = 1 - x;
@ -649,12 +646,10 @@ int ssd1306_draw_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
return err; return err;
} }
++y; ++y;
if (radius_err < 0) if (radius_err < 0) {
{
radius_err += 2 * y + 1; radius_err += 2 * y + 1;
} }
else else {
{
--x; --x;
radius_err += 2 * (y - x + 1); radius_err += 2 * (y - x + 1);
} }
@ -690,12 +685,10 @@ int ssd1306_fill_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
return err; return err;
} }
++x; ++x;
if (radius_err < 0) if (radius_err < 0) {
{
radius_err += 2 * x + 1; radius_err += 2 * x + 1;
} }
else else {
{
--y; --y;
radius_err += 2 * (x - y + 1); radius_err += 2 * (x - y + 1);
} }
@ -723,12 +716,10 @@ int ssd1306_fill_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
if ((err = ssd1306_draw_hline(dev, fb, x0 - x, y0 + y, x - x1 + 1, color))) if ((err = ssd1306_draw_hline(dev, fb, x0 - x, y0 + y, x - x1 + 1, color)))
return err; return err;
++y; ++y;
if (radius_err < 0) if (radius_err < 0) {
{
radius_err += 2 * y + 1; radius_err += 2 * y + 1;
} }
else else {
{
--x; --x;
radius_err += 2 * (y - x + 1); radius_err += 2 * (y - x + 1);
} }
@ -737,15 +728,16 @@ int ssd1306_fill_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
return 0; return 0;
} }
int ssd1306_draw_line(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0, int16_t x1, int16_t y1, ssd1306_color_t color) { int ssd1306_draw_line(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0,
int16_t x1, int16_t y1, ssd1306_color_t color)
{
if ((x0 >= dev->width) || (x0 < 0) || (y0 >= dev->height) || (y0 < 0)) if ((x0 >= dev->width) || (x0 < 0) || (y0 >= dev->height) || (y0 < 0))
return -EINVAL; return -EINVAL;
if ((x1 >= dev->width) || (x1 < 0) || (y1 >= dev->height) || (y1 < 0)) if ((x1 >= dev->width) || (x1 < 0) || (y1 >= dev->height) || (y1 < 0))
return -EINVAL; return -EINVAL;
int err; int err;
int16_t steep = abs(y1 - y0) > abs(x1 - x0); bool steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) { if (steep) {
swap(x0, y0); swap(x0, y0);
swap(x1, y1); swap(x1, y1);
@ -786,7 +778,10 @@ int ssd1306_draw_line(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0,
return 0; return 0;
} }
int ssd1306_draw_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, ssd1306_color_t color) { int ssd1306_draw_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0,
int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2,
ssd1306_color_t color)
{
int err; int err;
if ((err = ssd1306_draw_line(dev, fb, x0, y0, x1, y1, color))) if ((err = ssd1306_draw_line(dev, fb, x0, y0, x1, y1, color)))
return err; return err;
@ -795,8 +790,10 @@ int ssd1306_draw_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
return ssd1306_draw_line(dev, fb, x2, y2, x0, y0, color); return ssd1306_draw_line(dev, fb, x2, y2, x0, y0, color);
} }
int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0,int16_t x1, int16_t y1, int16_t x2, int16_t y2, ssd1306_color_t color) { int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0,
int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2,
ssd1306_color_t color)
{
int16_t a, b, y, last; int16_t a, b, y, last;
int err; int err;
@ -875,7 +872,9 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
return 0; return 0;
} }
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background) uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb,
const font_info_t *font, uint8_t x, uint8_t y, char c,
ssd1306_color_t foreground, ssd1306_color_t background)
{ {
uint8_t i, j; uint8_t i, j;
const uint8_t *bitmap; const uint8_t *bitmap;
@ -889,20 +888,15 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *
return 0; return 0;
bitmap = font->bitmap + d->offset; bitmap = font->bitmap + d->offset;
for (j = 0; j < font->height; ++j) for (j = 0; j < font->height; ++j) {
{ for (i = 0; i < d->width; ++i) {
for (i = 0; i < d->width; ++i) if (i % 8 == 0) {
{
if (i % 8 == 0)
{
line = bitmap[(d->width + 7) / 8 * j + i / 8]; // line data line = bitmap[(d->width + 7) / 8 * j + i / 8]; // line data
} }
if (line & 0x80) if (line & 0x80) {
{
ssd1306_draw_pixel(dev, fb, x + i, y + j, foreground); ssd1306_draw_pixel(dev, fb, x + i, y + j, foreground);
} }
else else {
{
switch (background) switch (background)
{ {
case OLED_COLOR_TRANSPARENT: case OLED_COLOR_TRANSPARENT:
@ -923,7 +917,9 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *
return d->width; return d->width;
} }
uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background) uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb,
const font_info_t *font, uint8_t x, uint8_t y, char *str,
ssd1306_color_t foreground, ssd1306_color_t background)
{ {
uint8_t t = x; uint8_t t = x;
@ -936,7 +932,6 @@ uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t
++str; ++str;
if (*str) if (*str)
x += font->c; x += font->c;
} }
return (x - t); return x - t;
} }

View file

@ -3,6 +3,7 @@
* *
* Copyright (c) 2016 urx (https://github.com/urx), * Copyright (c) 2016 urx (https://github.com/urx),
* Ruslan V. Uss (https://github.com/UncleRus) * Ruslan V. Uss (https://github.com/UncleRus)
* Zaltora (https://github.com/Zaltora)
* *
* MIT Licensed as described in the file LICENSE * MIT Licensed as described in the file LICENSE
*/ */
@ -289,7 +290,7 @@ int ssd1306_set_whole_display_lighting(const ssd1306_t *dev, bool light);
/** /**
* Draw one pixel * Draw one pixel
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x X coordinate * @param x X coordinate
* @param y Y coordinate * @param y Y coordinate
* @param color Color of the pixel * @param color Color of the pixel
@ -300,7 +301,7 @@ int ssd1306_draw_pixel(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y, ss
/** /**
* Draw a horizontal line * Draw a horizontal line
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x X coordinate or starting (left) point * @param x X coordinate or starting (left) point
* @param y Y coordinate or starting (left) point * @param y Y coordinate or starting (left) point
* @param w Line width * @param w Line width
@ -312,7 +313,7 @@ int ssd1306_draw_hline(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y, ui
/** /**
* Draw a vertical line * Draw a vertical line
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x X coordinate or starting (top) point * @param x X coordinate or starting (top) point
* @param y Y coordinate or starting (top) point * @param y Y coordinate or starting (top) point
* @param h Line height * @param h Line height
@ -324,7 +325,7 @@ int ssd1306_draw_vline(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y, ui
/** /**
* Draw a line * Draw a line
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x0 First x point coordinate * @param x0 First x point coordinate
* @param y0 First y point coordinate * @param y0 First y point coordinate
* @param x1 Second x point coordinate * @param x1 Second x point coordinate
@ -337,7 +338,7 @@ int ssd1306_draw_line(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t y0,
/** /**
* Draw a rectangle * Draw a rectangle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x X coordinate or starting (top left) point * @param x X coordinate or starting (top left) point
* @param y Y coordinate or starting (top left) point * @param y Y coordinate or starting (top left) point
* @param w Rectangle width * @param w Rectangle width
@ -350,7 +351,7 @@ int ssd1306_draw_rectangle(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y
/** /**
* Draw a filled rectangle * Draw a filled rectangle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x X coordinate or starting (top left) point * @param x X coordinate or starting (top left) point
* @param y Y coordinate or starting (top left) point * @param y Y coordinate or starting (top left) point
* @param w Rectangle width * @param w Rectangle width
@ -363,7 +364,7 @@ int ssd1306_fill_rectangle(const ssd1306_t *dev, uint8_t *fb, int8_t x, int8_t y
/** /**
* Draw a circle * Draw a circle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x0 X coordinate or center * @param x0 X coordinate or center
* @param y0 Y coordinate or center * @param y0 Y coordinate or center
* @param r Radius * @param r Radius
@ -375,7 +376,7 @@ int ssd1306_draw_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
/** /**
* Draw a filled circle * Draw a filled circle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x0 X coordinate or center * @param x0 X coordinate or center
* @param y0 Y coordinate or center * @param y0 Y coordinate or center
* @param r Radius * @param r Radius
@ -387,7 +388,7 @@ int ssd1306_fill_circle(const ssd1306_t *dev, uint8_t *fb, int8_t x0, int8_t y0,
/** /**
* Draw a triangle * Draw a triangle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x0 First x point coordinate * @param x0 First x point coordinate
* @param y0 First y point coordinate * @param y0 First y point coordinate
* @param x1 Second x point coordinate * @param x1 Second x point coordinate
@ -402,7 +403,7 @@ int ssd1306_draw_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
/** /**
* Draw a filled triangle * Draw a filled triangle
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param x0 First x point coordinate * @param x0 First x point coordinate
* @param y0 First y point coordinate * @param y0 First y point coordinate
* @param x1 Second x point coordinate * @param x1 Second x point coordinate
@ -417,7 +418,8 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
/** /**
* Draw one character using currently selected font * Draw one character using currently selected font
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param font Pointer to font info structure
* @param x X position of character (top-left corner) * @param x X position of character (top-left corner)
* @param y Y position of character (top-left corner) * @param y Y position of character (top-left corner)
* @param c The character to draw * @param c The character to draw
@ -425,12 +427,13 @@ int ssd1306_fill_triangle(const ssd1306_t *dev, uint8_t *fb, int16_t x0, int16_t
* @param background Background color * @param background Background color
* @return Width of the character * @return Width of the character
*/ */
uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *fnt, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background); uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background);
/** /**
* Draw one character using currently selected font * Draw one character using currently selected font
* @param dev Pointer to device descriptor * @param dev Pointer to device descriptor
* @param buf Pointer to framebuffer. Framebuffer size = width * height / 8 * @param fb Pointer to framebuffer. Framebuffer size = width * height / 8
* @param font Pointer to font info structure
* @param x X position of character (top-left corner) * @param x X position of character (top-left corner)
* @param y Y position of character (top-left corner) * @param y Y position of character (top-left corner)
* @param str The string to draw * @param str The string to draw
@ -438,7 +441,7 @@ uint8_t ssd1306_draw_char(const ssd1306_t *dev, uint8_t *fb, const font_info_t *
* @param background Background color * @param background Background color
* @return Width of the string (out-of-display pixels also included) * @return Width of the string (out-of-display pixels also included)
*/ */
uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t *fnt, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background); uint8_t ssd1306_draw_string(const ssd1306_t *dev, uint8_t *fb, const font_info_t *font, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"