add u8g2 and ui libs (#91)
* add u8g2 and ui libs * add display driver and usage example * not init display in test mode * change todo text * fix removed code * Target f2 (#107) * add ioc for flipperzero f2 * add generated f1 files to f2 * regenerate cubemx * invert initial state of led * blink backligh * shutdown backlight on idle
This commit is contained in:
3292
lib/u8g2/u8g2.h
Normal file
3292
lib/u8g2/u8g2.h
Normal file
File diff suppressed because it is too large
Load Diff
218
lib/u8g2/u8g2_bitmap.c
Normal file
218
lib/u8g2/u8g2_bitmap.c
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
|
||||
u8g2_bitmap.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent) {
|
||||
u8g2->bitmap_transparency = is_transparent;
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Position on the display
|
||||
len Length of bitmap line in pixel. Note: This differs from u8glib which had a bytecount here.
|
||||
b Pointer to the bitmap line.
|
||||
Only draw pixels which are set.
|
||||
*/
|
||||
|
||||
void u8g2_DrawHorizontalBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 128;
|
||||
while(len > 0)
|
||||
{
|
||||
if ( *b & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if ( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
x++;
|
||||
mask >>= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 128;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
/* u8glib compatible bitmap draw function */
|
||||
void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t w;
|
||||
w = cnt;
|
||||
w *= 8;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHorizontalBitmap(u8g2, x, y, w, bitmap);
|
||||
bitmap += cnt;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawHXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 1;
|
||||
while(len > 0) {
|
||||
if ( *b & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if ( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
x++;
|
||||
mask <<= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 1;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t blen;
|
||||
blen = w;
|
||||
blen += 7;
|
||||
blen >>= 3;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHXBM(u8g2, x, y, w, bitmap);
|
||||
bitmap += blen;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawHXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 1;
|
||||
while(len > 0)
|
||||
{
|
||||
if( u8x8_pgm_read(b) & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
x++;
|
||||
mask <<= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 1;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t blen;
|
||||
blen = w;
|
||||
blen += 7;
|
||||
blen >>= 3;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHXBMP(u8g2, x, y, w, bitmap);
|
||||
bitmap += blen;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
207
lib/u8g2/u8g2_box.c
Normal file
207
lib/u8g2/u8g2_box.c
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
|
||||
u8g2_box.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/*
|
||||
draw a filled box
|
||||
restriction: does not work for w = 0 or h = 0
|
||||
*/
|
||||
void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
while( h != 0 )
|
||||
{
|
||||
u8g2_DrawHVLine(u8g2, x, y, w, 0);
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
draw a frame (empty box)
|
||||
restriction: does not work for w = 0 or h = 0
|
||||
ToDo:
|
||||
pixel in the corners are drawn twice. This could be optimized.
|
||||
*/
|
||||
void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
|
||||
{
|
||||
u8g2_uint_t xtmp = x;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_DrawHVLine(u8g2, x, y, w, 0);
|
||||
u8g2_DrawHVLine(u8g2, x, y, h, 1);
|
||||
x+=w;
|
||||
x--;
|
||||
u8g2_DrawHVLine(u8g2, x, y, h, 1);
|
||||
y+=h;
|
||||
y--;
|
||||
u8g2_DrawHVLine(u8g2, xtmp, y, w, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
|
||||
{
|
||||
u8g2_uint_t xl, yu;
|
||||
u8g2_uint_t yl, xr;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
xl = x;
|
||||
xl += r;
|
||||
yu = y;
|
||||
yu += r;
|
||||
|
||||
xr = x;
|
||||
xr += w;
|
||||
xr -= r;
|
||||
xr -= 1;
|
||||
|
||||
yl = y;
|
||||
yl += h;
|
||||
yl -= r;
|
||||
yl -= 1;
|
||||
|
||||
u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
|
||||
u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
|
||||
u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
|
||||
u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
|
||||
|
||||
{
|
||||
u8g2_uint_t ww, hh;
|
||||
|
||||
ww = w;
|
||||
ww -= r;
|
||||
ww -= r;
|
||||
xl++;
|
||||
yu++;
|
||||
|
||||
if ( ww >= 3 )
|
||||
{
|
||||
ww -= 2;
|
||||
u8g2_DrawBox(u8g2, xl, y, ww, r+1);
|
||||
u8g2_DrawBox(u8g2, xl, yl, ww, r+1);
|
||||
}
|
||||
|
||||
hh = h;
|
||||
hh -= r;
|
||||
hh -= r;
|
||||
//h--;
|
||||
if ( hh >= 3 )
|
||||
{
|
||||
hh -= 2;
|
||||
u8g2_DrawBox(u8g2, x, yu, w, hh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
|
||||
{
|
||||
u8g2_uint_t xl, yu;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
xl = x;
|
||||
xl += r;
|
||||
yu = y;
|
||||
yu += r;
|
||||
|
||||
{
|
||||
u8g2_uint_t yl, xr;
|
||||
|
||||
xr = x;
|
||||
xr += w;
|
||||
xr -= r;
|
||||
xr -= 1;
|
||||
|
||||
yl = y;
|
||||
yl += h;
|
||||
yl -= r;
|
||||
yl -= 1;
|
||||
|
||||
u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
|
||||
u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
|
||||
u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
|
||||
u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
|
||||
}
|
||||
|
||||
{
|
||||
u8g2_uint_t ww, hh;
|
||||
|
||||
ww = w;
|
||||
ww -= r;
|
||||
ww -= r;
|
||||
hh = h;
|
||||
hh -= r;
|
||||
hh -= r;
|
||||
|
||||
xl++;
|
||||
yu++;
|
||||
|
||||
if ( ww >= 3 )
|
||||
{
|
||||
ww -= 2;
|
||||
h--;
|
||||
u8g2_DrawHLine(u8g2, xl, y, ww);
|
||||
u8g2_DrawHLine(u8g2, xl, y+h, ww);
|
||||
}
|
||||
|
||||
if ( hh >= 3 )
|
||||
{
|
||||
hh -= 2;
|
||||
w--;
|
||||
u8g2_DrawVLine(u8g2, x, yu, hh);
|
||||
u8g2_DrawVLine(u8g2, x+w, yu, hh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
213
lib/u8g2/u8g2_buffer.c
Normal file
213
lib/u8g2/u8g2_buffer.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
|
||||
u8g2_buffer.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <string.h>
|
||||
|
||||
/*============================================*/
|
||||
void u8g2_ClearBuffer(u8g2_t *u8g2)
|
||||
{
|
||||
size_t cnt;
|
||||
cnt = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
cnt *= u8g2->tile_buf_height;
|
||||
cnt *= 8;
|
||||
memset(u8g2->tile_buf_ptr, 0, cnt);
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
|
||||
static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_tile_row)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint16_t offset;
|
||||
uint8_t w;
|
||||
|
||||
w = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
offset = src_tile_row;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
offset *= w;
|
||||
offset *= 8;
|
||||
ptr += offset;
|
||||
u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
write the buffer to the display RAM.
|
||||
For most displays, this will make the content visible to the user.
|
||||
Some displays (like the SSD1606) require a u8x8_RefreshDisplay()
|
||||
*/
|
||||
static void u8g2_send_buffer(u8g2_t *u8g2) U8X8_NOINLINE;
|
||||
static void u8g2_send_buffer(u8g2_t *u8g2)
|
||||
{
|
||||
uint8_t src_row;
|
||||
uint8_t src_max;
|
||||
uint8_t dest_row;
|
||||
uint8_t dest_max;
|
||||
|
||||
src_row = 0;
|
||||
src_max = u8g2->tile_buf_height;
|
||||
dest_row = u8g2->tile_curr_row;
|
||||
dest_max = u8g2_GetU8x8(u8g2)->display_info->tile_height;
|
||||
|
||||
do
|
||||
{
|
||||
u8g2_send_tile_row(u8g2, src_row, dest_row);
|
||||
src_row++;
|
||||
dest_row++;
|
||||
} while( src_row < src_max && dest_row < dest_max );
|
||||
}
|
||||
|
||||
/* same as u8g2_send_buffer but also send the DISPLAY_REFRESH message (used by SSD1606) */
|
||||
void u8g2_SendBuffer(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_send_buffer(u8g2);
|
||||
u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
|
||||
{
|
||||
u8g2->tile_curr_row = row;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_FirstPage(u8g2_t *u8g2)
|
||||
{
|
||||
if ( u8g2->is_auto_page_clear )
|
||||
{
|
||||
u8g2_ClearBuffer(u8g2);
|
||||
}
|
||||
u8g2_SetBufferCurrTileRow(u8g2, 0);
|
||||
}
|
||||
|
||||
uint8_t u8g2_NextPage(u8g2_t *u8g2)
|
||||
{
|
||||
uint8_t row;
|
||||
u8g2_send_buffer(u8g2);
|
||||
row = u8g2->tile_curr_row;
|
||||
row += u8g2->tile_buf_height;
|
||||
if ( row >= u8g2_GetU8x8(u8g2)->display_info->tile_height )
|
||||
{
|
||||
u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
|
||||
return 0;
|
||||
}
|
||||
if ( u8g2->is_auto_page_clear )
|
||||
{
|
||||
u8g2_ClearBuffer(u8g2);
|
||||
}
|
||||
u8g2_SetBufferCurrTileRow(u8g2, row);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
Description:
|
||||
Update a sub area of the display, given by tile position, width and height.
|
||||
The arguments are "tile" coordinates. Any u8g2 rotation is ignored.
|
||||
This procedure only checks whether full buffer mode is active.
|
||||
There is no error checking for the arguments: It is the responsibility of the
|
||||
user to ensure, that the provided arguments are correct.
|
||||
|
||||
Limitations:
|
||||
- Only available in full buffer mode (will not do anything in page mode)
|
||||
- Tile positions and sizes (pixel position divided by 8)
|
||||
- Any display rotation/mirror is ignored
|
||||
- Only works with displays, which support U8x8 API
|
||||
- Will not send the e-paper refresh message (will probably not work with e-paper devices)
|
||||
*/
|
||||
void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
|
||||
{
|
||||
uint16_t page_size;
|
||||
uint8_t *ptr;
|
||||
|
||||
/* check, whether we are in full buffer mode */
|
||||
if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
|
||||
return; /* not in full buffer mode, do nothing */
|
||||
|
||||
page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
|
||||
|
||||
ptr = u8g2_GetBufferPtr(u8g2);
|
||||
ptr += tx*8;
|
||||
ptr += page_size*ty;
|
||||
|
||||
while( th > 0 )
|
||||
{
|
||||
u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
|
||||
ptr += page_size;
|
||||
ty++;
|
||||
th--;
|
||||
}
|
||||
}
|
||||
|
||||
/* same as sendBuffer, but does not send the ePaper refresh message */
|
||||
void u8g2_UpdateDisplay(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_send_buffer(u8g2);
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
|
||||
/* vertical_top memory architecture */
|
||||
void u8g2_WriteBufferPBM(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
|
||||
}
|
||||
|
||||
void u8g2_WriteBufferXBM(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
|
||||
}
|
||||
|
||||
|
||||
/* horizontal right memory architecture */
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_WriteBufferPBM2(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
|
||||
}
|
||||
|
||||
void u8g2_WriteBufferXBM2(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
|
||||
}
|
||||
|
479
lib/u8g2/u8g2_circle.c
Normal file
479
lib/u8g2/u8g2_circle.c
Normal file
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
|
||||
u8g2_circle.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/*==============================================*/
|
||||
/* Circle */
|
||||
|
||||
static void u8g2_draw_circle_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
|
||||
static void u8g2_draw_circle_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 - y);
|
||||
u8g2_DrawPixel(u8g2, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 - y);
|
||||
u8g2_DrawPixel(u8g2, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 + y);
|
||||
u8g2_DrawPixel(u8g2, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 + y);
|
||||
u8g2_DrawPixel(u8g2, x0 - y, y0 + x);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_circle(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g2_int_t f;
|
||||
u8g2_int_t ddF_x;
|
||||
u8g2_int_t ddF_y;
|
||||
u8g2_uint_t x;
|
||||
u8g2_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g2_draw_circle_section(u8g2, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g2_draw_circle_section(u8g2, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawCircle(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rad, y0-rad, x0+rad+1, y0+rad+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
|
||||
/* draw circle */
|
||||
u8g2_draw_circle(u8g2, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Disk */
|
||||
|
||||
static void u8g2_draw_disc_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
|
||||
static void u8g2_draw_disc_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0-y, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0+y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0-y, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0-y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0+y, y0, x+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0-y, y0, x+1);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_disc(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g2_int_t f;
|
||||
u8g2_int_t ddF_x;
|
||||
u8g2_int_t ddF_y;
|
||||
u8g2_uint_t x;
|
||||
u8g2_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g2_draw_disc_section(u8g2, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g2_draw_disc_section(u8g2, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawDisc(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rad, y0-rad, x0+rad+1, y0+rad+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
/* draw disc */
|
||||
u8g2_draw_disc(u8g2, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Ellipse */
|
||||
|
||||
/*
|
||||
Source:
|
||||
Foley, Computer Graphics, p 90
|
||||
*/
|
||||
static void u8g2_draw_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
static void u8g2_draw_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 - y);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 - y);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 + y);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 + y);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_ellipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g2_uint_t x, y;
|
||||
u8g2_long_t xchg, ychg;
|
||||
u8g2_long_t err;
|
||||
u8g2_long_t rxrx2;
|
||||
u8g2_long_t ryry2;
|
||||
u8g2_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g2_draw_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g2_draw_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g2_DrawEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rx, y0-ry, x0+rx+1, y0+ry+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_draw_ellipse(u8g2, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Filled Ellipse */
|
||||
|
||||
static void u8g2_draw_filled_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
static void u8g2_draw_filled_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0, y+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0, y+1);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_filled_ellipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g2_uint_t x, y;
|
||||
u8g2_long_t xchg, ychg;
|
||||
u8g2_long_t err;
|
||||
u8g2_long_t rxrx2;
|
||||
u8g2_long_t ryry2;
|
||||
u8g2_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g2_draw_filled_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g2_draw_filled_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g2_DrawFilledEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rx, y0-ry, x0+rx+1, y0+ry+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_draw_filled_ellipse(u8g2, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
||||
|
1458
lib/u8g2/u8g2_d_memory.c
Normal file
1458
lib/u8g2/u8g2_d_memory.c
Normal file
File diff suppressed because it is too large
Load Diff
5366
lib/u8g2/u8g2_d_setup.c
Normal file
5366
lib/u8g2/u8g2_d_setup.c
Normal file
File diff suppressed because it is too large
Load Diff
1291
lib/u8g2/u8g2_font.c
Normal file
1291
lib/u8g2/u8g2_font.c
Normal file
File diff suppressed because it is too large
Load Diff
343578
lib/u8g2/u8g2_fonts.c
Normal file
343578
lib/u8g2/u8g2_fonts.c
Normal file
File diff suppressed because it is too large
Load Diff
255
lib/u8g2/u8g2_hvline.c
Normal file
255
lib/u8g2/u8g2_hvline.c
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
|
||||
u8g2_hvline.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Calltree
|
||||
|
||||
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
u8g2->cb->draw_l90
|
||||
u8g2_draw_hv_line_2dir
|
||||
u8g2->ll_hvline(u8g2, x, y, len, dir);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <assert.h>
|
||||
|
||||
/*==========================================================*/
|
||||
/* intersection procedure */
|
||||
|
||||
/*
|
||||
Description:
|
||||
clip range from pos a (included) with line len (a+len excluded) agains c (included) to d (excluded)
|
||||
Assumptions:
|
||||
len > 0
|
||||
c <= d (this is not checked)
|
||||
will return 0 if there is no intersection and if a > b
|
||||
|
||||
*/
|
||||
|
||||
static uint8_t u8g2_clip_intersection2(u8g2_uint_t *ap, u8g2_uint_t *len, u8g2_uint_t c, u8g2_uint_t d)
|
||||
{
|
||||
u8g2_uint_t a = *ap;
|
||||
u8g2_uint_t b;
|
||||
b = a;
|
||||
b += *len;
|
||||
|
||||
/*
|
||||
Description:
|
||||
clip range from a (included) to b (excluded) agains c (included) to d (excluded)
|
||||
Assumptions:
|
||||
a <= b (violation is checked and handled correctly)
|
||||
c <= d (this is not checked)
|
||||
will return 0 if there is no intersection and if a > b
|
||||
|
||||
optimized clipping: c is set to 0 --> 27 Oct 2018: again removed the c==0 assumption
|
||||
|
||||
replaced by uint8_t u8g2_clip_intersection2
|
||||
*/
|
||||
|
||||
/* handle the a>b case correctly. If code and time is critical, this could */
|
||||
/* be removed completly (be aware about memory curruption for wrong */
|
||||
/* arguments) or return 0 for a>b (will lead to skipped lines for wrong */
|
||||
/* arguments) */
|
||||
|
||||
/* removing the following if clause completly may lead to memory corruption of a>b */
|
||||
if ( a > b )
|
||||
{
|
||||
/* replacing this if with a simple "return 0;" will not handle the case with negative a */
|
||||
if ( a < d )
|
||||
{
|
||||
b = d;
|
||||
b--;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* from now on, the asumption a <= b is ok */
|
||||
|
||||
if ( a >= d )
|
||||
return 0;
|
||||
if ( b <= c )
|
||||
return 0;
|
||||
if ( a < c )
|
||||
a = c;
|
||||
if ( b > d )
|
||||
b = d;
|
||||
|
||||
*ap = a;
|
||||
b -= a;
|
||||
*len = b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*==========================================================*/
|
||||
/* draw procedures */
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the pixel buffer
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
This function first adjusts the y position to the local buffer. Then it
|
||||
will clip the line and call u8g2_draw_low_level_hv_line()
|
||||
|
||||
*/
|
||||
void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
|
||||
/* clipping happens before the display rotation */
|
||||
|
||||
/* transform to pixel buffer coordinates */
|
||||
y -= u8g2->pixel_curr_row;
|
||||
|
||||
u8g2->ll_hvline(u8g2, x, y, len, dir);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This is the toplevel function for the hv line draw procedures.
|
||||
This function should be called by the user.
|
||||
|
||||
"dir" may have 4 directions: 0 (left to right), 1, 2, 3 (down up)
|
||||
*/
|
||||
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
/* Make a call to the callback function (e.g. u8g2_draw_l90_r0). */
|
||||
/* The callback may rotate the hv line */
|
||||
/* after rotation this will call u8g2_draw_hv_line_4dir() */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
if ( u8g2->is_page_clip_window_intersection != 0 )
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
if ( len != 0 )
|
||||
{
|
||||
|
||||
/* convert to two directions */
|
||||
if ( len > 1 )
|
||||
{
|
||||
if ( dir == 2 )
|
||||
{
|
||||
x -= len;
|
||||
x++;
|
||||
}
|
||||
else if ( dir == 3 )
|
||||
{
|
||||
y -= len;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
dir &= 1;
|
||||
|
||||
/* clip against the user window */
|
||||
if ( dir == 0 )
|
||||
{
|
||||
if ( y < u8g2->user_y0 )
|
||||
return;
|
||||
if ( y >= u8g2->user_y1 )
|
||||
return;
|
||||
if ( u8g2_clip_intersection2(&x, &len, u8g2->user_x0, u8g2->user_x1) == 0 )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( x < u8g2->user_x0 )
|
||||
return;
|
||||
if ( x >= u8g2->user_x1 )
|
||||
return;
|
||||
if ( u8g2_clip_intersection2(&y, &len, u8g2->user_y0, u8g2->user_y1) == 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
u8g2->cb->draw_l90(u8g2, x, y, len, dir);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
// #ifdef U8G2_WITH_INTERSECTION
|
||||
// if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
// return;
|
||||
// #endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 0);
|
||||
}
|
||||
|
||||
void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
// #ifdef U8G2_WITH_INTERSECTION
|
||||
// if ( u8g2_IsIntersection(u8g2, x, y, x+1, y+len) == 0 )
|
||||
// return;
|
||||
// #endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 1);
|
||||
}
|
||||
|
||||
void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( y < u8g2->user_y0 )
|
||||
return;
|
||||
if ( y >= u8g2->user_y1 )
|
||||
return;
|
||||
if ( x < u8g2->user_x0 )
|
||||
return;
|
||||
if ( x >= u8g2->user_x1 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
Assign the draw color for all drawing functions.
|
||||
color may be 0 or 1. The actual color is defined by the display.
|
||||
With color = 1 the drawing function will set the display memory to 1.
|
||||
For OLEDs this ususally means, that the pixel is enabled and the LED
|
||||
at the pixel is turned on.
|
||||
On an LCD it usually means that the LCD segment of the pixel is enabled,
|
||||
which absorbs the light.
|
||||
For eInk/ePaper it means black ink.
|
||||
|
||||
7 Jan 2017: Allow color value 2 for XOR operation.
|
||||
|
||||
*/
|
||||
void u8g2_SetDrawColor(u8g2_t *u8g2, uint8_t color)
|
||||
{
|
||||
u8g2->draw_color = color; /* u8g2_SetDrawColor: just assign the argument */
|
||||
if ( color >= 3 )
|
||||
u8g2->draw_color = 1; /* u8g2_SetDrawColor: make color as one if arg is invalid */
|
||||
}
|
||||
|
176
lib/u8g2/u8g2_intersection.c
Normal file
176
lib/u8g2/u8g2_intersection.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
|
||||
u8g2_intersection.c
|
||||
|
||||
Intersection calculation, code taken from u8g_clip.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define U8G2_ALWAYS_INLINE __inline__ __attribute__((always_inline))
|
||||
#else
|
||||
#define U8G2_ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(U8G2_WITH_INTERSECTION) || defined(U8G2_WITH_CLIP_WINDOW_SUPPORT)
|
||||
|
||||
#ifdef OLD_VERSION_WITH_SYMETRIC_BOUNDARIES
|
||||
|
||||
/*
|
||||
intersection assumptions:
|
||||
a1 <= a2 is always true
|
||||
|
||||
minimized version
|
||||
---1----0 1 b1 <= a2 && b1 > b2
|
||||
-----1--0 1 b2 >= a1 && b1 > b2
|
||||
---1-1--- 1 b1 <= a2 && b2 >= a1
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
calculate the intersection between a0/a1 and v0/v1
|
||||
The intersection check returns one if the range of a0/a1 has an intersection with v0/v1.
|
||||
The intersection check includes the boundary values v1 and a1.
|
||||
|
||||
The following asserts will succeed:
|
||||
assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(4, 6, 6, 9) != 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(6, 9, 4, 6) != 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(7, 9, 4, 6) == 0 );
|
||||
*/
|
||||
|
||||
//static uint8_t U8G2_ALWAYS_INLINE u8g2_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
static uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
|
||||
{
|
||||
if ( v0 <= a1 )
|
||||
{
|
||||
if ( v1 >= a0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v0 > v1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v1 >= a0 )
|
||||
{
|
||||
if ( v0 > v1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* OLD_VERSION_WITH_SYMETRIC_BOUNDARIES */
|
||||
|
||||
|
||||
/*
|
||||
version with asymetric boundaries.
|
||||
a1 and v1 are excluded
|
||||
v0 == v1 is not support end return 1
|
||||
*/
|
||||
uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
|
||||
{
|
||||
if ( v0 < a1 ) // v0 <= a1
|
||||
{
|
||||
if ( v1 > a0 ) // v1 >= a0
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v0 > v1 ) // v0 > v1
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v1 > a0 ) // v1 >= a0
|
||||
{
|
||||
if ( v0 > v1 ) // v0 > v1
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* upper limits are not included (asymetric boundaries) */
|
||||
uint8_t u8g2_IsIntersection(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
|
||||
{
|
||||
if ( u8g2_is_intersection_decision_tree(u8g2->user_y0, u8g2->user_y1, y0, y1) == 0 )
|
||||
return 0;
|
||||
|
||||
return u8g2_is_intersection_decision_tree(u8g2->user_x0, u8g2->user_x1, x0, x1);
|
||||
}
|
||||
|
||||
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
371
lib/u8g2/u8g2_ll_hvline.c
Normal file
371
lib/u8g2/u8g2_ll_hvline.c
Normal file
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
|
||||
u8g2_ll_hvline.c
|
||||
|
||||
low level hvline
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*ptr |= or_mask
|
||||
*ptr ^= xor_mask
|
||||
|
||||
color = 0: or_mask = 1, xor_mask = 1
|
||||
color = 1: or_mask = 1, xor_mask = 0
|
||||
color = 2: or_mask = 0, xor_mask = 1
|
||||
|
||||
if ( color <= 1 )
|
||||
or_mask = mask;
|
||||
if ( color != 1 )
|
||||
xor_mask = mask;
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <assert.h>
|
||||
|
||||
/*=================================================*/
|
||||
/*
|
||||
u8g2_ll_hvline_vertical_top_lsb
|
||||
SSD13xx
|
||||
UC1701
|
||||
*/
|
||||
|
||||
|
||||
#ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
uint8_t or_mask, xor_mask;
|
||||
#ifdef __unix
|
||||
uint8_t *max_ptr = u8g2->tile_buf_ptr + u8g2_GetU8x8(u8g2)->display_info->tile_width*u8g2->tile_buf_height*8;
|
||||
#endif
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = y; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 1;
|
||||
mask <<= bit_pos;
|
||||
|
||||
or_mask = 0;
|
||||
xor_mask = 0;
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
or_mask = mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
xor_mask = mask;
|
||||
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset &= ~7;
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
ptr += x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
#ifdef __unix
|
||||
assert(ptr < max_ptr);
|
||||
#endif
|
||||
*ptr |= or_mask;
|
||||
*ptr ^= xor_mask;
|
||||
ptr++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
#ifdef __unix
|
||||
assert(ptr < max_ptr);
|
||||
#endif
|
||||
*ptr |= or_mask;
|
||||
*ptr ^= xor_mask;
|
||||
|
||||
bit_pos++;
|
||||
bit_pos &= 7;
|
||||
|
||||
len--;
|
||||
|
||||
if ( bit_pos == 0 )
|
||||
{
|
||||
ptr+=u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
or_mask = 1;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
xor_mask = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
or_mask <<= 1;
|
||||
xor_mask <<= 1;
|
||||
}
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
/*
|
||||
x,y position within the buffer
|
||||
*/
|
||||
static void u8g2_draw_pixel_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = y; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 1;
|
||||
mask <<= bit_pos;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset &= ~7;
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
ptr += x;
|
||||
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
|
||||
x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
|
||||
y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
/*=================================================*/
|
||||
/*
|
||||
u8g2_ll_hvline_horizontal_right_lsb
|
||||
ST7920
|
||||
*/
|
||||
|
||||
#ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos;
|
||||
uint8_t mask;
|
||||
uint8_t tile_width = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
|
||||
bit_pos = x; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 128;
|
||||
mask >>= bit_pos;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset *= tile_width;
|
||||
offset += x>>3;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
mask >>= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 128;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
//x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
ptr += tile_width;
|
||||
//y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
|
||||
/*
|
||||
x,y position within the buffer
|
||||
*/
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
static void u8g2_draw_pixel_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = x; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 128;
|
||||
mask >>= bit_pos;
|
||||
x >>= 3;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
offset += x;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
|
||||
x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
|
||||
y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
451
lib/u8g2/u8g2_setup.c
Normal file
451
lib/u8g2/u8g2_setup.c
Normal file
@@ -0,0 +1,451 @@
|
||||
/*
|
||||
|
||||
u8g2_setup.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/*============================================*/
|
||||
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
|
||||
void u8g2_SetMaxClipWindow(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->clip_x0 = 0;
|
||||
u8g2->clip_y0 = 0;
|
||||
u8g2->clip_x1 = (u8g2_uint_t)~(u8g2_uint_t)0;
|
||||
u8g2->clip_y1 = (u8g2_uint_t)~(u8g2_uint_t)0;
|
||||
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_SetClipWindow(u8g2_t *u8g2, u8g2_uint_t clip_x0, u8g2_uint_t clip_y0, u8g2_uint_t clip_x1, u8g2_uint_t clip_y1 )
|
||||
{
|
||||
u8g2->clip_x0 = clip_x0;
|
||||
u8g2->clip_y0 = clip_y0;
|
||||
u8g2->clip_x1 = clip_x1;
|
||||
u8g2->clip_y1 = clip_y1;
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
This procedure is called after setting up the display (u8x8 structure).
|
||||
--> This is the central init procedure for u8g2 object
|
||||
*/
|
||||
void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_draw_ll_hvline_cb ll_hvline_cb, const u8g2_cb_t *u8g2_cb)
|
||||
{
|
||||
u8g2->font = NULL;
|
||||
//u8g2->kerning = NULL;
|
||||
//u8g2->get_kerning_cb = u8g2_GetNullKerning;
|
||||
|
||||
//u8g2->ll_hvline = u8g2_ll_hvline_vertical_top_lsb;
|
||||
u8g2->ll_hvline = ll_hvline_cb;
|
||||
|
||||
u8g2->tile_buf_ptr = buf;
|
||||
u8g2->tile_buf_height = tile_buf_height;
|
||||
|
||||
u8g2->tile_curr_row = 0;
|
||||
|
||||
u8g2->font_decode.is_transparent = 0; /* issue 443 */
|
||||
u8g2->bitmap_transparency = 0;
|
||||
|
||||
u8g2->draw_color = 1;
|
||||
u8g2->is_auto_page_clear = 1;
|
||||
|
||||
u8g2->cb = u8g2_cb;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_SetMaxClipWindow(u8g2); /* assign a clip window and call the update() procedure */
|
||||
#else
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
#endif
|
||||
|
||||
u8g2_SetFontPosBaseline(u8g2); /* issue 195 */
|
||||
|
||||
#ifdef U8G2_WITH_FONT_ROTATION
|
||||
u8g2->font_decode.dir = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Usually the display rotation is set initially, but it could be done later also
|
||||
u8g2_cb can be U8G2_R0..U8G2_R3
|
||||
*/
|
||||
void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
|
||||
{
|
||||
u8g2->cb = u8g2_cb;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
|
||||
void u8g2_SendF(u8g2_t * u8g2, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
u8x8_cad_vsendf(u8g2_GetU8x8(u8g2), fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
update dimension:
|
||||
calculate the following variables:
|
||||
u8g2_uint_t buf_x0; left corner of the buffer
|
||||
u8g2_uint_t buf_x1; right corner of the buffer (excluded)
|
||||
u8g2_uint_t buf_y0;
|
||||
u8g2_uint_t buf_y1;
|
||||
*/
|
||||
|
||||
static void u8g2_update_dimension_common(u8g2_t *u8g2)
|
||||
{
|
||||
const u8x8_display_info_t *display_info = u8g2_GetU8x8(u8g2)->display_info;
|
||||
u8g2_uint_t t;
|
||||
|
||||
t = u8g2->tile_buf_height;
|
||||
t *= 8;
|
||||
u8g2->pixel_buf_height = t;
|
||||
|
||||
t = display_info->tile_width;
|
||||
#ifndef U8G2_16BIT
|
||||
if ( t >= 32 )
|
||||
t = 31;
|
||||
#endif
|
||||
t *= 8;
|
||||
u8g2->pixel_buf_width = t;
|
||||
|
||||
t = u8g2->tile_curr_row;
|
||||
t *= 8;
|
||||
u8g2->pixel_curr_row = t;
|
||||
|
||||
t = u8g2->tile_buf_height;
|
||||
/* handle the case, where the buffer is larger than the (remaining) part of the display */
|
||||
if ( t + u8g2->tile_curr_row > display_info->tile_height )
|
||||
t = display_info->tile_height - u8g2->tile_curr_row;
|
||||
t *= 8;
|
||||
|
||||
u8g2->buf_y0 = u8g2->pixel_curr_row;
|
||||
u8g2->buf_y1 = u8g2->buf_y0;
|
||||
u8g2->buf_y1 += t;
|
||||
|
||||
|
||||
#ifdef U8G2_16BIT
|
||||
u8g2->width = display_info->pixel_width;
|
||||
u8g2->height = display_info->pixel_height;
|
||||
#else
|
||||
u8g2->width = 240;
|
||||
if ( display_info->pixel_width <= 240 )
|
||||
u8g2->width = display_info->pixel_width;
|
||||
u8g2->height = display_info->pixel_height;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*==========================================================*/
|
||||
/* apply clip window */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
static void u8g2_apply_clip_window(u8g2_t *u8g2)
|
||||
{
|
||||
/* check aganst the current user_??? window */
|
||||
if ( u8g2_IsIntersection(u8g2, u8g2->clip_x0, u8g2->clip_y0, u8g2->clip_x1, u8g2->clip_y1) == 0 )
|
||||
{
|
||||
u8g2->is_page_clip_window_intersection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g2->is_page_clip_window_intersection = 1;
|
||||
|
||||
if ( u8g2->user_x0 < u8g2->clip_x0 )
|
||||
u8g2->user_x0 = u8g2->clip_x0;
|
||||
if ( u8g2->user_x1 > u8g2->clip_x1 )
|
||||
u8g2->user_x1 = u8g2->clip_x1;
|
||||
if ( u8g2->user_y0 < u8g2->clip_y0 )
|
||||
u8g2->user_y0 = u8g2->clip_y0;
|
||||
if ( u8g2->user_y1 > u8g2->clip_y1 )
|
||||
u8g2->user_y1 = u8g2->clip_y1;
|
||||
}
|
||||
}
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
|
||||
/*==========================================================*/
|
||||
|
||||
|
||||
void u8g2_update_dimension_r0(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r0(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = 0;
|
||||
u8g2->user_x1 = u8g2->width; /* pixel_buf_width replaced with width */
|
||||
|
||||
u8g2->user_y0 = u8g2->buf_y0;
|
||||
u8g2->user_y1 = u8g2->buf_y1;
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
void u8g2_update_dimension_r1(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
|
||||
u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
|
||||
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;
|
||||
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r1(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = u8g2->buf_y0;
|
||||
u8g2->user_x1 = u8g2->buf_y1;
|
||||
|
||||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->height; /* pixel_buf_width replaced with height (which is the real pixel width) */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
void u8g2_update_dimension_r2(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r2(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = 0;
|
||||
u8g2->user_x1 = u8g2->width; /* pixel_buf_width replaced with width */
|
||||
|
||||
/* there are ases where the height is not a multiple of 8. */
|
||||
/* in such a case u8g2->buf_y1 might be heigher than u8g2->height */
|
||||
u8g2->user_y0 = 0;
|
||||
if ( u8g2->height >= u8g2->buf_y1 )
|
||||
u8g2->user_y0 = u8g2->height - u8g2->buf_y1;
|
||||
u8g2->user_y1 = u8g2->height - u8g2->buf_y0;
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
void u8g2_update_dimension_r3(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
|
||||
u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
|
||||
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;
|
||||
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r3(u8g2_t *u8g2)
|
||||
{
|
||||
/* there are ases where the height is not a multiple of 8. */
|
||||
/* in such a case u8g2->buf_y1 might be heigher than u8g2->width */
|
||||
u8g2->user_x0 = 0;
|
||||
if ( u8g2->width >= u8g2->buf_y1 )
|
||||
u8g2->user_x0 = u8g2->width - u8g2->buf_y1;
|
||||
u8g2->user_x1 = u8g2->width - u8g2->buf_y0;
|
||||
|
||||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->height; /* pixel_buf_width replaced with height (pixel_width) */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
extern void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
|
||||
|
||||
|
||||
void u8g2_draw_l90_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
#ifdef __unix
|
||||
assert( dir <= 1 );
|
||||
#endif
|
||||
u8g2_draw_hv_line_2dir(u8g2, x, y, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_mirrorr_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx;
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
if ( (dir & 1) == 0 )
|
||||
{
|
||||
xx -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
xx--;
|
||||
}
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, y, len, dir);
|
||||
}
|
||||
|
||||
/* dir = 0 or 1 */
|
||||
void u8g2_draw_l90_r1(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
#ifdef __unix
|
||||
assert( dir <= 1 );
|
||||
#endif
|
||||
|
||||
yy = x;
|
||||
|
||||
xx = u8g2->height;
|
||||
xx -= y;
|
||||
xx--;
|
||||
|
||||
dir ++;
|
||||
if ( dir == 2 )
|
||||
{
|
||||
xx -= len;
|
||||
xx++;
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_r2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
/*
|
||||
yy = u8g2->height;
|
||||
yy -= y;
|
||||
yy--;
|
||||
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
xx--;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
xx -= len;
|
||||
xx++;
|
||||
}
|
||||
else if ( dir == 1 )
|
||||
{
|
||||
yy -= len;
|
||||
yy++;
|
||||
}
|
||||
*/
|
||||
|
||||
yy = u8g2->height;
|
||||
yy -= y;
|
||||
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
yy--;
|
||||
xx -= len;
|
||||
}
|
||||
else if ( dir == 1 )
|
||||
{
|
||||
xx--;
|
||||
yy -= len;
|
||||
}
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_r3(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
xx = y;
|
||||
|
||||
yy = u8g2->width;
|
||||
yy -= x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
yy--;
|
||||
yy -= len;
|
||||
yy++;
|
||||
dir = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
yy--;
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================*/
|
||||
const u8g2_cb_t u8g2_cb_r0 = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_r0 };
|
||||
const u8g2_cb_t u8g2_cb_r1 = { u8g2_update_dimension_r1, u8g2_update_page_win_r1, u8g2_draw_l90_r1 };
|
||||
const u8g2_cb_t u8g2_cb_r2 = { u8g2_update_dimension_r2, u8g2_update_page_win_r2, u8g2_draw_l90_r2 };
|
||||
const u8g2_cb_t u8g2_cb_r3 = { u8g2_update_dimension_r3, u8g2_update_page_win_r3, u8g2_draw_l90_r3 };
|
||||
|
||||
const u8g2_cb_t u8g2_cb_mirror = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_mirrorr_r0 };
|
||||
|
||||
/*============================================*/
|
||||
/* setup for the null device */
|
||||
|
||||
/* setup for the null (empty) device */
|
||||
void u8g2_Setup_null(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
|
||||
{
|
||||
static uint8_t buf[8];
|
||||
u8g2_SetupDisplay(u8g2, u8x8_d_null_cb, u8x8_cad_empty, byte_cb, gpio_and_delay_cb);
|
||||
u8g2_SetupBuffer(u8g2, buf, 1, u8g2_ll_hvline_vertical_top_lsb, rotation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
1198
lib/u8g2/u8x8.h
Normal file
1198
lib/u8g2/u8x8.h
Normal file
File diff suppressed because it is too large
Load Diff
493
lib/u8g2/u8x8_8x8.c
Normal file
493
lib/u8g2/u8x8_8x8.c
Normal file
@@ -0,0 +1,493 @@
|
||||
/*
|
||||
|
||||
u8x8_8x8.c
|
||||
|
||||
font procedures, directly interfaces display procedures
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
#if defined(ESP8266)
|
||||
uint8_t u8x8_pgm_read_esp(const uint8_t * addr)
|
||||
{
|
||||
uint32_t bytes;
|
||||
bytes = *(uint32_t*)((uint32_t)addr & ~3);
|
||||
return ((uint8_t*)&bytes)[(uint32_t)addr & 3];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void u8x8_SetFont(u8x8_t *u8x8, const uint8_t *font_8x8)
|
||||
{
|
||||
u8x8->font = font_8x8;
|
||||
}
|
||||
|
||||
/*
|
||||
Args:
|
||||
u8x8: ptr to u8x8 structure
|
||||
encoding: glyph for which the data is requested (must be between 0 and 255)
|
||||
buf: pointer to 8 bytes
|
||||
*/
|
||||
static void u8x8_get_glyph_data(u8x8_t *u8x8, uint8_t encoding, uint8_t *buf, uint8_t tile_offset) U8X8_NOINLINE;
|
||||
static void u8x8_get_glyph_data(u8x8_t *u8x8, uint8_t encoding, uint8_t *buf, uint8_t tile_offset)
|
||||
{
|
||||
uint8_t first, last, tiles, i;
|
||||
uint16_t offset;
|
||||
first = u8x8_pgm_read(u8x8->font+0);
|
||||
last = u8x8_pgm_read(u8x8->font+1);
|
||||
tiles = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
tiles *= u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
|
||||
/* get the glyph bitmap from the font */
|
||||
if ( first <= encoding && encoding <= last )
|
||||
{
|
||||
offset = encoding;
|
||||
offset -= first;
|
||||
offset *= tiles; /* new 2019 format */
|
||||
offset += tile_offset; /* new 2019 format */
|
||||
offset *= 8;
|
||||
offset +=4; /* changed from 2 to 4, new 2019 format */
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] = u8x8_pgm_read(u8x8->font+offset);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* invert the bitmap if required */
|
||||
if ( u8x8->is_font_inverse_mode )
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] ^= 255;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8x8_DrawGlyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
uint8_t buf[8];
|
||||
th += x;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
u8x8_DrawTile(u8x8, xx, y, 1, buf);
|
||||
tile++;
|
||||
xx++;
|
||||
} while( xx < th );
|
||||
y++;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Source: http://graphics.stanford.edu/~seander/bithacks.html
|
||||
Section: Interleave bits by Binary Magic Numbers
|
||||
Original codes is here:
|
||||
static const unsigned int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF};
|
||||
static const unsigned int S[] = {1, 2, 4, 8};
|
||||
|
||||
unsigned int x; // Interleave lower 16 bits of x and y, so the bits of x
|
||||
unsigned int y; // are in the even positions and bits from y in the odd;
|
||||
unsigned int z; // z gets the resulting 32-bit Morton Number.
|
||||
// x and y must initially be less than 65536.
|
||||
|
||||
x = (x | (x << S[3])) & B[3];
|
||||
x = (x | (x << S[2])) & B[2];
|
||||
x = (x | (x << S[1])) & B[1];
|
||||
x = (x | (x << S[0])) & B[0];
|
||||
|
||||
y = (y | (y << S[3])) & B[3];
|
||||
y = (y | (y << S[2])) & B[2];
|
||||
y = (y | (y << S[1])) & B[1];
|
||||
y = (y | (y << S[0])) & B[0];
|
||||
|
||||
z = x | (y << 1);
|
||||
*/
|
||||
uint16_t u8x8_upscale_byte(uint8_t x)
|
||||
{
|
||||
uint16_t y = x;
|
||||
y |= (y << 4); // x = (x | (x << S[2])) & B[2];
|
||||
y &= 0x0f0f;
|
||||
y |= (y << 2); // x = (x | (x << S[1])) & B[1];
|
||||
y &= 0x3333;
|
||||
y |= (y << 1); // x = (x | (x << S[0])) & B[0];
|
||||
y &= 0x5555;
|
||||
|
||||
y |= (y << 1); // z = x | (y << 1);
|
||||
return y;
|
||||
}
|
||||
|
||||
static void u8x8_upscale_buf(uint8_t *src, uint8_t *dest) U8X8_NOINLINE;
|
||||
static void u8x8_upscale_buf(uint8_t *src, uint8_t *dest)
|
||||
{
|
||||
uint8_t i = 4;
|
||||
do
|
||||
{
|
||||
*dest++ = *src;
|
||||
*dest++ = *src++;
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
}
|
||||
|
||||
static void u8x8_draw_2x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding, uint8_t tile)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t t;
|
||||
uint8_t buf[8];
|
||||
uint8_t buf1[8];
|
||||
uint8_t buf2[8];
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
for( i = 0; i < 8; i ++ )
|
||||
{
|
||||
t = u8x8_upscale_byte(buf[i]);
|
||||
buf1[i] = t >> 8;
|
||||
buf2[i] = t & 255;
|
||||
}
|
||||
u8x8_upscale_buf(buf2, buf);
|
||||
u8x8_DrawTile(u8x8, x, y, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf2+4, buf);
|
||||
u8x8_DrawTile(u8x8, x+1, y, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf1, buf);
|
||||
u8x8_DrawTile(u8x8, x, y+1, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf1+4, buf);
|
||||
u8x8_DrawTile(u8x8, x+1, y+1, 1, buf);
|
||||
}
|
||||
|
||||
|
||||
void u8x8_Draw2x2Glyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
th *= 2;
|
||||
th += x;
|
||||
tv *= 2;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_draw_2x2_subglyph(u8x8, xx, y, encoding, tile);
|
||||
tile++;
|
||||
xx+=2;
|
||||
} while( xx < th );
|
||||
y+=2;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
/* https://github.com/olikraus/u8g2/issues/474 */
|
||||
static void u8x8_draw_1x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding, uint8_t tile)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t t;
|
||||
uint8_t buf[8];
|
||||
uint8_t buf1[8];
|
||||
uint8_t buf2[8];
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
for( i = 0; i < 8; i ++ )
|
||||
{
|
||||
t = u8x8_upscale_byte(buf[i]);
|
||||
buf1[i] = t >> 8;
|
||||
buf2[i] = t & 255;
|
||||
}
|
||||
u8x8_DrawTile(u8x8, x, y, 1, buf2);
|
||||
u8x8_DrawTile(u8x8, x, y+1, 1, buf1);
|
||||
}
|
||||
|
||||
void u8x8_Draw1x2Glyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
th += x;
|
||||
tv *= 2;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_draw_1x2_subglyph(u8x8, xx, y, encoding, tile);
|
||||
tile++;
|
||||
xx++;
|
||||
} while( xx < th );
|
||||
y+=2;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
/*
|
||||
source: https://en.wikipedia.org/wiki/UTF-8
|
||||
Bits from to bytes Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
|
||||
7 U+0000 U+007F 1 0xxxxxxx
|
||||
11 U+0080 U+07FF 2 110xxxxx 10xxxxxx
|
||||
16 U+0800 U+FFFF 3 1110xxxx 10xxxxxx 10xxxxxx
|
||||
21 U+10000 U+1FFFFF 4 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
26 U+200000 U+3FFFFFF 5 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
31 U+4000000 U+7FFFFFFF 6 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* reset the internal state machine */
|
||||
void u8x8_utf8_init(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->utf8_state = 0; /* also reset during u8x8_SetupDefaults() */
|
||||
}
|
||||
|
||||
uint16_t u8x8_ascii_next(U8X8_UNUSED u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
if ( b == 0 || b == '\n' ) /* '\n' terminates the string to support the string list procedures */
|
||||
return 0x0ffff; /* end of string detected*/
|
||||
return b;
|
||||
}
|
||||
|
||||
/*
|
||||
pass a byte from an utf8 encoded string to the utf8 decoder state machine
|
||||
returns
|
||||
0x0fffe: no glyph, just continue
|
||||
0x0ffff: end of string
|
||||
anything else: The decoded encoding
|
||||
*/
|
||||
uint16_t u8x8_utf8_next(u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
if ( b == 0 || b == '\n' ) /* '\n' terminates the string to support the string list procedures */
|
||||
return 0x0ffff; /* end of string detected, pending UTF8 is discarded */
|
||||
if ( u8x8->utf8_state == 0 )
|
||||
{
|
||||
if ( b >= 0xfc ) /* 6 byte sequence */
|
||||
{
|
||||
u8x8->utf8_state = 5;
|
||||
b &= 1;
|
||||
}
|
||||
else if ( b >= 0xf8 )
|
||||
{
|
||||
u8x8->utf8_state = 4;
|
||||
b &= 3;
|
||||
}
|
||||
else if ( b >= 0xf0 )
|
||||
{
|
||||
u8x8->utf8_state = 3;
|
||||
b &= 7;
|
||||
}
|
||||
else if ( b >= 0xe0 )
|
||||
{
|
||||
u8x8->utf8_state = 2;
|
||||
b &= 15;
|
||||
}
|
||||
else if ( b >= 0xc0 )
|
||||
{
|
||||
u8x8->utf8_state = 1;
|
||||
b &= 0x01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* do nothing, just use the value as encoding */
|
||||
return b;
|
||||
}
|
||||
u8x8->encoding = b;
|
||||
return 0x0fffe;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8x8->utf8_state--;
|
||||
/* The case b < 0x080 (an illegal UTF8 encoding) is not checked here. */
|
||||
u8x8->encoding<<=6;
|
||||
b &= 0x03f;
|
||||
u8x8->encoding |= b;
|
||||
if ( u8x8->utf8_state != 0 )
|
||||
return 0x0fffe; /* nothing to do yet */
|
||||
}
|
||||
return u8x8->encoding;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_DrawGlyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_DrawString(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_DrawUTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_2x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_2x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
|
||||
th <<= 1;
|
||||
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_Draw2x2Glyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_Draw2x2String(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_2x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_Draw2x2UTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_2x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_1x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_1x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_Draw1x2Glyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_Draw1x2String(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_1x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_Draw1x2UTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_1x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t u8x8_GetUTF8Len(u8x8_t *u8x8, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8_utf8_next(u8x8, *s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
666
lib/u8g2/u8x8_byte.c
Normal file
666
lib/u8g2/u8x8_byte.c
Normal file
@@ -0,0 +1,666 @@
|
||||
/*
|
||||
|
||||
u8x8_byte.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_byte_SetDC(u8x8_t *u8x8, uint8_t dc)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_SET_DC, dc, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_SendBytes(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_SEND, cnt, (void *)data);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_SendByte(u8x8_t *u8x8, uint8_t byte)
|
||||
{
|
||||
return u8x8_byte_SendBytes(u8x8, 1, &byte);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_StartTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_START_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_EndTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_END_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_empty(U8X8_UNUSED u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
break; /* do nothing */
|
||||
}
|
||||
return 1; /* always succeed */
|
||||
}
|
||||
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
|
||||
/*
|
||||
Uses:
|
||||
u8x8->display_info->sda_setup_time_ns
|
||||
u8x8->display_info->sck_pulse_width_ns
|
||||
u8x8->display_info->spi_mode
|
||||
u8x8->display_info->chip_disable_level
|
||||
u8x8->display_info->chip_enable_level
|
||||
u8x8->display_info->post_chip_enable_wait_ns
|
||||
u8x8->display_info->pre_chip_disable_wait_ns
|
||||
Calls to GPIO and DELAY:
|
||||
U8X8_MSG_DELAY_NANO
|
||||
U8X8_MSG_GPIO_DC
|
||||
U8X8_MSG_GPIO_CS
|
||||
U8X8_MSG_GPIO_CLOCK
|
||||
U8X8_MSG_GPIO_DATA
|
||||
Handles:
|
||||
U8X8_MSG_BYTE_INIT
|
||||
U8X8_MSG_BYTE_SEND
|
||||
U8X8_MSG_BYTE_SET_DC
|
||||
U8X8_MSG_BYTE_START_TRANSFER
|
||||
U8X8_MSG_BYTE_END_TRANSFER
|
||||
*/
|
||||
|
||||
uint8_t u8x8_byte_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
uint8_t takeover_edge = u8x8_GetSPIClockPhase(u8x8);
|
||||
uint8_t not_takeover_edge = 1 - takeover_edge;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
if ( b & 128 )
|
||||
u8x8_gpio_SetSPIData(u8x8, 1);
|
||||
else
|
||||
u8x8_gpio_SetSPIData(u8x8, 0);
|
||||
b <<= 1;
|
||||
|
||||
u8x8_gpio_SetSPIClock(u8x8, not_takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sda_setup_time_ns);
|
||||
u8x8_gpio_SetSPIClock(u8x8, takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sck_pulse_width_ns);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* no wait required here */
|
||||
|
||||
/* for SPI: setup correct level of the clock signal */
|
||||
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSPIClockPhase(u8x8));
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_8bit_6800mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is high */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_8bit_8080mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is high */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t *data;
|
||||
uint8_t takeover_edge = u8x8_GetSPIClockPhase(u8x8);
|
||||
uint8_t not_takeover_edge = 1 - takeover_edge;
|
||||
uint16_t b;
|
||||
static uint8_t last_dc;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
if ( last_dc != 0 )
|
||||
b |= 256;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = 0; i < 9; i++ )
|
||||
{
|
||||
if ( b & 256 )
|
||||
u8x8_gpio_SetSPIData(u8x8, 1);
|
||||
else
|
||||
u8x8_gpio_SetSPIData(u8x8, 0);
|
||||
b <<= 1;
|
||||
|
||||
u8x8_gpio_SetSPIClock(u8x8, not_takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sda_setup_time_ns);
|
||||
u8x8_gpio_SetSPIClock(u8x8, takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sck_pulse_width_ns);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* no wait required here */
|
||||
|
||||
/* for SPI: setup correct level of the clock signal */
|
||||
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSPIClockPhase(u8x8));
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
last_dc = arg_int;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
void u8x8_byte_set_ks0108_cs(u8x8_t *u8x8, uint8_t arg)
|
||||
{
|
||||
u8x8_gpio_SetCS(u8x8, arg&1);
|
||||
arg = arg >> 1;
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS1, arg&1);
|
||||
arg = arg >> 1;
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS2, arg&1);
|
||||
}
|
||||
|
||||
/* 6800 mode */
|
||||
uint8_t u8x8_byte_ks0108(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is low */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
/* expects 3 bits in arg_int for the chip select lines */
|
||||
u8x8_byte_set_ks0108_cs(u8x8, arg_int);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_byte_set_ks0108_cs(u8x8, arg_int);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* sed1520 or sbn1661
|
||||
U8X8_MSG_GPIO_E --> E1
|
||||
U8X8_MSG_GPIO_CS --> E2
|
||||
*/
|
||||
uint8_t u8x8_byte_sed1520(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
static uint8_t enable_pin;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, enable_pin, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 200); /* KS0108 requires 450 ns, use 200 here */
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns); /* expect 250 here */
|
||||
u8x8_gpio_call(u8x8, enable_pin, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signals are low */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS, 0);
|
||||
enable_pin = U8X8_MSG_GPIO_E;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
/* cs lines are not supported for the SED1520/SBN1661 */
|
||||
/* instead, this will select the E1 or E2 line */
|
||||
enable_pin = U8X8_MSG_GPIO_E;
|
||||
if ( arg_int != 0 )
|
||||
enable_pin = U8X8_MSG_GPIO_CS;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
|
||||
/*
|
||||
software i2c,
|
||||
ignores ACK response (which is anyway not provided by some displays)
|
||||
also does not allow reading from the device
|
||||
*/
|
||||
static void i2c_delay(u8x8_t *u8x8) U8X8_NOINLINE;
|
||||
static void i2c_delay(u8x8_t *u8x8)
|
||||
{
|
||||
//u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_10MICRO, u8x8->display_info->i2c_bus_clock_100kHz);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_I2C, u8x8->display_info->i2c_bus_clock_100kHz);
|
||||
}
|
||||
|
||||
static void i2c_init(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8_gpio_SetI2CClock(u8x8, 1);
|
||||
u8x8_gpio_SetI2CData(u8x8, 1);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
}
|
||||
|
||||
/* actually, the scl line is not observed, so this procedure does not return a value */
|
||||
|
||||
static void i2c_read_scl_and_delay(u8x8_t *u8x8)
|
||||
{
|
||||
/* set as input (line will be high) */
|
||||
u8x8_gpio_SetI2CClock(u8x8, 1);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
}
|
||||
|
||||
static void i2c_clear_scl(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8_gpio_SetI2CClock(u8x8, 0);
|
||||
}
|
||||
|
||||
static void i2c_read_sda(u8x8_t *u8x8)
|
||||
{
|
||||
/* set as input (line will be high) */
|
||||
u8x8_gpio_SetI2CData(u8x8, 1);
|
||||
}
|
||||
|
||||
static void i2c_clear_sda(u8x8_t *u8x8)
|
||||
{
|
||||
/* set open collector and drive low */
|
||||
u8x8_gpio_SetI2CData(u8x8, 0);
|
||||
}
|
||||
|
||||
static void i2c_start(u8x8_t *u8x8)
|
||||
{
|
||||
if ( u8x8->i2c_started != 0 )
|
||||
{
|
||||
/* if already started: do restart */
|
||||
i2c_read_sda(u8x8); /* SDA = 1 */
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
}
|
||||
i2c_read_sda(u8x8);
|
||||
/* send the start condition, both lines go from 1 to 0 */
|
||||
i2c_clear_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
u8x8->i2c_started = 1;
|
||||
}
|
||||
|
||||
|
||||
static void i2c_stop(u8x8_t *u8x8)
|
||||
{
|
||||
/* set SDA to 0 */
|
||||
i2c_clear_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
|
||||
/* now release all lines */
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
|
||||
/* set SDA to 1 */
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
u8x8->i2c_started = 0;
|
||||
}
|
||||
|
||||
static void i2c_write_bit(u8x8_t *u8x8, uint8_t val)
|
||||
{
|
||||
if (val)
|
||||
i2c_read_sda(u8x8);
|
||||
else
|
||||
i2c_clear_sda(u8x8);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
}
|
||||
|
||||
static void i2c_read_bit(u8x8_t *u8x8)
|
||||
{
|
||||
//uint8_t val;
|
||||
/* do not drive SDA */
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
//return val;
|
||||
}
|
||||
|
||||
static void i2c_write_byte(u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
i2c_write_bit(u8x8, b & 128);
|
||||
i2c_write_bit(u8x8, b & 64);
|
||||
i2c_write_bit(u8x8, b & 32);
|
||||
i2c_write_bit(u8x8, b & 16);
|
||||
i2c_write_bit(u8x8, b & 8);
|
||||
i2c_write_bit(u8x8, b & 4);
|
||||
i2c_write_bit(u8x8, b & 2);
|
||||
i2c_write_bit(u8x8, b & 1);
|
||||
|
||||
/* read ack from client */
|
||||
/* 0: ack was given by client */
|
||||
/* 1: nothing happend during ack cycle */
|
||||
i2c_read_bit(u8x8);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_sw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
i2c_write_byte(u8x8, *data);
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
i2c_init(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
i2c_start(u8x8);
|
||||
i2c_write_byte(u8x8, u8x8_GetI2CAddress(u8x8));
|
||||
//i2c_write_byte(u8x8, 0x078);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
i2c_stop(u8x8);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
/* alternative i2c byte procedure */
|
||||
#ifdef ALTERNATIVE_I2C_BYTE_PROCEDURE
|
||||
|
||||
|
||||
void i2c_transfer(u8x8_t *u8x8, uint8_t adr, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
uint8_t i;
|
||||
i2c_start(u8x8);
|
||||
i2c_write_byte(u8x8, adr);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
i2c_write_byte(u8x8, data[i]);
|
||||
i2c_stop(u8x8);
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_byte_sw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t buffer[32]; /* u8g2/u8x8 will never send more than 32 bytes */
|
||||
static uint8_t buf_idx;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
buffer[buf_idx++] = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
i2c_init(u8x8); /* init i2c communication */
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
/* ignored for i2c */
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
buf_idx = 0;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
i2c_transfer(u8x8, u8x8_GetI2CAddress(u8x8), buf_idx, buffer);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
749
lib/u8g2/u8x8_cad.c
Normal file
749
lib/u8g2/u8x8_cad.c
Normal file
@@ -0,0 +1,749 @@
|
||||
/*
|
||||
|
||||
u8x8_cad.c
|
||||
|
||||
"command arg data" interface to the graphics controller
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
The following sequence must be used for any data, which is set to the display:
|
||||
|
||||
|
||||
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
|
||||
|
||||
any of the following calls
|
||||
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
|
||||
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
|
||||
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
|
||||
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/*
|
||||
uint8_t u8x8_cad_template(u8x8_t *u8x8, uint8_t msg, uint16_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 1);
|
||||
u8x8_mcd_byte_Send(mcd->next, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 1);
|
||||
u8x8_mcd_byte_Send(mcd->next, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 0);
|
||||
for( i = 0; i < 8; i++ )
|
||||
u8x8_mcd_byte_Send(mcd->next, ((uint8_t *)arg_ptr)[i]);
|
||||
break;
|
||||
case U8X8_MSG_CAD_RESET:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_CMD, cmd, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendMultipleArg(u8x8_t *u8x8, uint8_t cnt, uint8_t arg)
|
||||
{
|
||||
while( cnt > 0 )
|
||||
{
|
||||
u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
|
||||
cnt--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, cnt, data);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_cad_vsendf(u8x8_t * u8x8, const char *fmt, va_list va)
|
||||
{
|
||||
uint8_t d;
|
||||
u8x8_cad_StartTransfer(u8x8);
|
||||
while( *fmt != '\0' )
|
||||
{
|
||||
d = (uint8_t)va_arg(va, int);
|
||||
switch(*fmt)
|
||||
{
|
||||
case 'a': u8x8_cad_SendArg(u8x8, d); break;
|
||||
case 'c': u8x8_cad_SendCmd(u8x8, d); break;
|
||||
case 'd': u8x8_cad_SendData(u8x8, 1, &d); break;
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
u8x8_cad_EndTransfer(u8x8);
|
||||
}
|
||||
|
||||
void u8x8_SendF(u8x8_t * u8x8, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
u8x8_cad_vsendf(u8x8, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
/*
|
||||
21 c send command c
|
||||
22 a send arg a
|
||||
23 d send data d
|
||||
24 CS on
|
||||
25 CS off
|
||||
254 milli delay by milliseconds
|
||||
255 end of sequence
|
||||
*/
|
||||
|
||||
void u8x8_cad_SendSequence(u8x8_t *u8x8, uint8_t const *data)
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t v;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
cmd = *data;
|
||||
data++;
|
||||
switch( cmd )
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
v = *data;
|
||||
u8x8->cad_cb(u8x8, cmd, v, NULL);
|
||||
data++;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
v = *data;
|
||||
u8x8_cad_SendData(u8x8, 1, &v);
|
||||
data++;
|
||||
break;
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
u8x8->cad_cb(u8x8, cmd, 0, NULL);
|
||||
break;
|
||||
case 0x0fe:
|
||||
v = *data;
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, v);
|
||||
data++;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_cad_empty(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 1 for commands and args and
|
||||
dc = 0 for data
|
||||
*/
|
||||
uint8_t u8x8_cad_110(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 1 for commands and args and
|
||||
dc = 0 for data
|
||||
t6963
|
||||
*/
|
||||
uint8_t u8x8_cad_100(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 0 for commands and args and
|
||||
dc = 1 for data
|
||||
*/
|
||||
uint8_t u8x8_cad_001(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 0 for commands
|
||||
dc = 1 for args and data
|
||||
*/
|
||||
uint8_t u8x8_cad_011(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad procedure for the ST7920 in SPI mode */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
uint8_t u8x8_cad_st7920_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *data;
|
||||
uint8_t b;
|
||||
uint8_t i;
|
||||
static uint8_t buf[16];
|
||||
uint8_t *ptr;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SendByte(u8x8, 0x0f8);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int << 4);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, 0x0f8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int << 4);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
|
||||
u8x8_byte_SendByte(u8x8, 0x0fa);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
|
||||
/* this loop should be optimized: multiple bytes should be sent */
|
||||
/* u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr); */
|
||||
data = (uint8_t *)arg_ptr;
|
||||
|
||||
/* the following loop increases speed by 20% */
|
||||
while( arg_int >= 8 )
|
||||
{
|
||||
i = 8;
|
||||
ptr = buf;
|
||||
do
|
||||
{
|
||||
b = *data++;
|
||||
*ptr++= b & 0x0f0;
|
||||
b <<= 4;
|
||||
*ptr++= b;
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
arg_int -= 8;
|
||||
u8x8_byte_SendBytes(u8x8, 16, buf);
|
||||
}
|
||||
|
||||
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
u8x8_byte_SendByte(u8x8, b & 0x0f0);
|
||||
u8x8_byte_SendByte(u8x8, b << 4);
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* cad procedure for the SSD13xx family in I2C mode */
|
||||
/* this procedure is also used by the ST7588 */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
/* U8X8_MSG_BYTE_START_TRANSFER starts i2c transfer, U8X8_MSG_BYTE_END_TRANSFER stops transfer */
|
||||
/* After transfer start, a full byte indicates command or data mode */
|
||||
|
||||
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr) U8X8_NOINLINE;
|
||||
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x040);
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, arg_ptr);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
}
|
||||
|
||||
/* classic version: will put a start/stop condition around each command and arg */
|
||||
uint8_t u8x8_cad_ssd13xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
/* 7 Nov 2016: Can this be improved? */
|
||||
//u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
//u8x8_byte_SendByte(u8x8, u8x8_GetI2CAddress(u8x8));
|
||||
u8x8_byte_SendByte(u8x8, 0x000);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
//u8x8_byte_SetDC(u8x8, 1);
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
/* cad transfer commands are ignored */
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* fast version with reduced data start/stops, issue 735 */
|
||||
uint8_t u8x8_cad_ssd13xx_fast_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
/* improved version, takeover from ld7032 */
|
||||
/* assumes, that the args of a command is not longer than 31 bytes */
|
||||
/* speed improvement is about 4% compared to the classic version */
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
/* lightning version: can replace the improved version from above */
|
||||
/* the drawback of the lightning version is this: The complete init sequence */
|
||||
/* must fit into the 32 byte Arduino Wire buffer, which might not always be the case */
|
||||
/* speed improvement is about 6% compared to the classic version */
|
||||
// if ( in_transfer == 0 )
|
||||
// {
|
||||
// u8x8_byte_StartTransfer(u8x8);
|
||||
// u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
|
||||
// in_transfer = 1;
|
||||
// }
|
||||
//u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* the st75256 i2c driver is a copy of the ssd13xx driver, but with arg=1 */
|
||||
/* modified from cad001 (ssd13xx) to cad011 */
|
||||
uint8_t u8x8_cad_st75256_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x000);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x040);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
/* see ssd13xx driver */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078; /* ST75256, often this is 0x07e */
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
/* cad transfer commands are ignored */
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad i2c procedure for the ld7032 controller */
|
||||
/* Issue https://github.com/olikraus/u8g2/issues/865 mentiones, that I2C does not work */
|
||||
/* Workaround is to remove the while loop (or increase the value in the condition) */
|
||||
uint8_t u8x8_cad_ld7032_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
//u8x8_byte_SetDC(u8x8, 1);
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x08); /* data write for LD7032 */
|
||||
}
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x060;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad procedure for the UC16xx family in I2C mode */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
/* DC bit is encoded into the adr byte */
|
||||
uint8_t u8x8_cad_uc16xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
static uint8_t is_data = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data != 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data == 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
in_transfer = 1;
|
||||
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
|
||||
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x070;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
/* actual start is delayed, because we do not whether this is data or cmd transfer */
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
1242
lib/u8g2/u8x8_d_st7565.c
Normal file
1242
lib/u8g2/u8x8_d_st7565.c
Normal file
File diff suppressed because it is too large
Load Diff
165
lib/u8g2/u8x8_display.c
Normal file
165
lib/u8g2/u8x8_display.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
|
||||
u8x8_display.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Abstraction layer for the graphics controller.
|
||||
Main goal is the placement of a 8x8 pixel block (tile) on the display.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
/* internal library function */
|
||||
|
||||
/*
|
||||
this is a helper function for the U8X8_MSG_DISPLAY_SETUP_MEMORY function.
|
||||
It can be called within the display callback function to carry out the usual standard tasks.
|
||||
|
||||
*/
|
||||
void u8x8_d_helper_display_setup_memory(u8x8_t *u8x8, const u8x8_display_info_t *display_info)
|
||||
{
|
||||
/* 1) set display info struct */
|
||||
u8x8->display_info = display_info;
|
||||
u8x8->x_offset = u8x8->display_info->default_x_offset;
|
||||
}
|
||||
|
||||
/*
|
||||
this is a helper function for the U8X8_MSG_DISPLAY_INIT function.
|
||||
It can be called within the display callback function to carry out the usual standard tasks.
|
||||
|
||||
*/
|
||||
void u8x8_d_helper_display_init(u8x8_t *u8x8)
|
||||
{
|
||||
/* 2) apply port directions to the GPIO lines and apply default values for the IO lines*/
|
||||
u8x8_gpio_Init(u8x8);
|
||||
u8x8_cad_Init(u8x8);
|
||||
|
||||
/* 3) do reset */
|
||||
u8x8_gpio_SetReset(u8x8, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
|
||||
u8x8_gpio_SetReset(u8x8, 0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
|
||||
u8x8_gpio_SetReset(u8x8, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->post_reset_wait_ms);
|
||||
}
|
||||
|
||||
/*==========================================*/
|
||||
/* official functions */
|
||||
|
||||
uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr)
|
||||
{
|
||||
u8x8_tile_t tile;
|
||||
tile.x_pos = x;
|
||||
tile.y_pos = y;
|
||||
tile.cnt = cnt;
|
||||
tile.tile_ptr = tile_ptr;
|
||||
return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile);
|
||||
}
|
||||
|
||||
/* should be implemented as macro */
|
||||
void u8x8_SetupMemory(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SETUP_MEMORY, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_InitDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_INIT, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_POWER_SAVE, is_enable, NULL);
|
||||
}
|
||||
|
||||
void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, mode, NULL);
|
||||
}
|
||||
|
||||
void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL);
|
||||
}
|
||||
|
||||
void u8x8_RefreshDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
|
||||
{
|
||||
u8x8_tile_t tile;
|
||||
uint8_t h;
|
||||
|
||||
tile.x_pos = 0;
|
||||
tile.cnt = 1;
|
||||
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
|
||||
|
||||
h = u8x8->display_info->tile_height;
|
||||
tile.y_pos = 0;
|
||||
do
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
|
||||
tile.y_pos++;
|
||||
} while( tile.y_pos < h );
|
||||
}
|
||||
|
||||
void u8x8_ClearDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
u8x8_ClearDisplayWithTile(u8x8, buf);
|
||||
}
|
||||
|
||||
void u8x8_FillDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t buf[8] = { 255, 255, 255, 255, 255, 255, 255, 255 };
|
||||
u8x8_ClearDisplayWithTile(u8x8, buf);
|
||||
}
|
||||
|
||||
void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
|
||||
{
|
||||
uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
u8x8_tile_t tile;
|
||||
if ( line < u8x8->display_info->tile_height )
|
||||
{
|
||||
tile.x_pos = 0;
|
||||
tile.y_pos = line;
|
||||
tile.cnt = 1;
|
||||
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
|
||||
}
|
||||
}
|
50
lib/u8g2/u8x8_gpio.c
Normal file
50
lib/u8g2/u8x8_gpio.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
|
||||
u8x8_gpio.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
void u8x8_gpio_call(u8x8_t *u8x8, uint8_t msg, uint8_t arg)
|
||||
{
|
||||
u8x8->gpio_and_delay_cb(u8x8, msg, arg, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
void u8x8_gpio_Delay(u8x8_t *u8x8, uint8_t msg, uint8_t dly)
|
||||
{
|
||||
u8x8->gpio_and_delay_cb(u8x8, msg, dly, NULL);
|
||||
}
|
||||
*/
|
147
lib/u8g2/u8x8_setup.c
Normal file
147
lib/u8g2/u8x8_setup.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
|
||||
u8x8_setup.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
/* universal dummy callback, which will be default for all callbacks */
|
||||
uint8_t u8x8_dummy_cb(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
/* the dummy callback will not handle any message and will fail for all messages */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const u8x8_display_info_t u8x8_null_display_info =
|
||||
{
|
||||
/* chip_enable_level = */ 0,
|
||||
/* chip_disable_level = */ 1,
|
||||
|
||||
/* post_chip_enable_wait_ns = */ 0,
|
||||
/* pre_chip_disable_wait_ns = */ 0,
|
||||
/* reset_pulse_width_ms = */ 0,
|
||||
/* post_reset_wait_ms = */ 0,
|
||||
/* sda_setup_time_ns = */ 0,
|
||||
/* sck_pulse_width_ns = */ 0, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
|
||||
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
|
||||
/* spi_mode = */ 0, /* active high, rising edge */
|
||||
/* i2c_bus_clock_100kHz = */ 4,
|
||||
/* data_setup_time_ns = */ 0,
|
||||
/* write_pulse_width_ns = */ 0,
|
||||
/* tile_width = */ 1, /* 8x8 */
|
||||
/* tile_hight = */ 1,
|
||||
/* default_x_offset = */ 0,
|
||||
/* flipmode_x_offset = */ 0,
|
||||
/* pixel_width = */ 8,
|
||||
/* pixel_height = */ 8
|
||||
};
|
||||
|
||||
|
||||
/* a special null device */
|
||||
uint8_t u8x8_d_null_cb(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_null_display_info);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
break;
|
||||
}
|
||||
/* the null device callback will succeed for all messages */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Description:
|
||||
Setup u8x8
|
||||
Args:
|
||||
u8x8 An empty u8x8 structure
|
||||
*/
|
||||
void u8x8_SetupDefaults(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_info = NULL;
|
||||
u8x8->display_cb = u8x8_dummy_cb;
|
||||
u8x8->cad_cb = u8x8_dummy_cb;
|
||||
u8x8->byte_cb = u8x8_dummy_cb;
|
||||
u8x8->gpio_and_delay_cb = u8x8_dummy_cb;
|
||||
u8x8->is_font_inverse_mode = 0;
|
||||
//u8x8->device_address = 0;
|
||||
u8x8->utf8_state = 0; /* also reset by u8x8_utf8_init */
|
||||
u8x8->bus_clock = 0; /* issue 769 */
|
||||
u8x8->i2c_address = 255;
|
||||
u8x8->debounce_default_pin_state = 255; /* assume all low active buttons */
|
||||
|
||||
#ifdef U8X8_USE_PINS
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < U8X8_PIN_CNT; i++ )
|
||||
u8x8->pins[i] = U8X8_PIN_NONE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Description:
|
||||
Setup u8x8 and assign the callback function. The dummy
|
||||
callback "u8x8_dummy_cb" can be used, if no callback is required.
|
||||
This setup will not communicate with the display itself.
|
||||
Use u8x8_InitDisplay() to send the startup code to the Display.
|
||||
Args:
|
||||
u8x8 An empty u8x8 structure
|
||||
display_cb Display/controller specific callback function
|
||||
cad_cb Display controller specific communication callback function
|
||||
byte_cb Display controller/communication specific callback funtion
|
||||
gpio_and_delay_cb Environment specific callback function
|
||||
|
||||
*/
|
||||
void u8x8_Setup(u8x8_t *u8x8, u8x8_msg_cb display_cb, u8x8_msg_cb cad_cb, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
|
||||
{
|
||||
/* setup defaults and reset pins to U8X8_PIN_NONE */
|
||||
u8x8_SetupDefaults(u8x8);
|
||||
|
||||
/* setup specific callbacks */
|
||||
u8x8->display_cb = display_cb;
|
||||
u8x8->cad_cb = cad_cb;
|
||||
u8x8->byte_cb = byte_cb;
|
||||
u8x8->gpio_and_delay_cb = gpio_and_delay_cb;
|
||||
|
||||
/* setup display info */
|
||||
u8x8_SetupMemory(u8x8);
|
||||
}
|
||||
|
106
lib/u8g2_vendor/u8g2_vendor.c
Normal file
106
lib/u8g2_vendor/u8g2_vendor.c
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "u8g2_support.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
|
||||
// #define DEBUG 1
|
||||
|
||||
uint8_t u8g2_gpio_and_delay_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
|
||||
switch(msg){
|
||||
//Initialize SPI peripheral
|
||||
case U8X8_MSG_GPIO_AND_DELAY_INIT:
|
||||
/* HAL initialization contains all what we need so we can skip this part. */
|
||||
break;
|
||||
|
||||
//Function which implements a delay, arg_int contains the amount of ms
|
||||
case U8X8_MSG_DELAY_MILLI:
|
||||
osDelay(arg_int);
|
||||
break;
|
||||
|
||||
//Function which delays 10us
|
||||
case U8X8_MSG_DELAY_10MICRO:
|
||||
delay_us(10);
|
||||
break;
|
||||
|
||||
//Function which delays 100ns
|
||||
case U8X8_MSG_DELAY_100NANO:
|
||||
asm("nop");
|
||||
break;
|
||||
|
||||
//Function to define the logic level of the RESET line
|
||||
case U8X8_MSG_GPIO_RESET:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] rst %d\n", arg_int);
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] unknown io %d\n", msg);
|
||||
#endif
|
||||
|
||||
return 0; //A message was received which is not implemented, return 0 to indicate an error
|
||||
}
|
||||
|
||||
return 1; // command processed successfully.
|
||||
}
|
||||
|
||||
uint8_t u8x8_hw_spi_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr){
|
||||
switch (msg) {
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]);
|
||||
#endif
|
||||
|
||||
HAL_SPI_Transmit(&hspi1, (uint8_t *)arg_ptr, arg_int, 10000);
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] dc %d\n", arg_int);
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] init\n");
|
||||
#endif
|
||||
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] start\n");
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
|
||||
asm("nop");
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] end\n");
|
||||
#endif
|
||||
|
||||
asm("nop");
|
||||
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
printf("[u8g2] unknown xfer %d\n", msg);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
4
lib/u8g2_vendor/u8g2_vendor.h
Normal file
4
lib/u8g2_vendor/u8g2_vendor.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "u8g2/u8g2.h"
|
||||
|
||||
uint8_t u8g2_gpio_and_delay_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
uint8_t u8x8_hw_spi_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
589
lib/ui/ui.cpp
Normal file
589
lib/ui/ui.cpp
Normal file
@@ -0,0 +1,589 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" {
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "u8g2_support.h"
|
||||
#include "u8g2/u8g2.h"
|
||||
}
|
||||
|
||||
#include "ui.h"
|
||||
#include "events.h"
|
||||
|
||||
// function draw basic layout -- single bmp
|
||||
void draw_bitmap(const char* bitmap, u8g2_t* u8g2, ScreenArea area) {
|
||||
if(bitmap == NULL) {
|
||||
printf("[basic layout] no content\n");
|
||||
u8g2_SetFont(u8g2, u8g2_font_6x10_mf);
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
u8g2_SetFontMode(u8g2, 1);
|
||||
u8g2_DrawStr(u8g2, 2, 12, "no content");
|
||||
} else {
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
u8g2_DrawXBM(u8g2, 0, 0, area.x + area.width, area.y + area.height, (unsigned char*)bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_text(const char* text, u8g2_t* u8g2, ScreenArea area) {
|
||||
// TODO proper cleanup statusbar
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
u8g2_DrawBox(u8g2, 0, 0, area.x + area.width, area.y + area.height);
|
||||
|
||||
Block text_block = Block {
|
||||
width: area.width,
|
||||
height: area.height,
|
||||
margin_left: 0,
|
||||
margin_top: 0,
|
||||
padding_left: 3,
|
||||
padding_top: 7,
|
||||
background: 0,
|
||||
color: 1,
|
||||
font: (uint8_t*)u8g2_font_6x10_mf,
|
||||
};
|
||||
|
||||
draw_block(u8g2, text, text_block, area.x, area.y);
|
||||
}
|
||||
|
||||
// draw layout and switch between ui item by button and timer
|
||||
void LayoutComponent::handle(Event* event, Store* store, u8g2_t* u8g2, ScreenArea area) {
|
||||
switch(event->type) {
|
||||
// get button event
|
||||
case EventTypeButton:
|
||||
if(event->value.button.state) {
|
||||
for(size_t i = 0; i < this->actions_size; i++) {
|
||||
FlipperComponent* next = NULL;
|
||||
|
||||
switch(this->actions[i].action) {
|
||||
case LayoutActionUp:
|
||||
if(event->value.button.id == ButtonsUp) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
case LayoutActionDown:
|
||||
if(event->value.button.id == ButtonsDown) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
case LayoutActionLeft:
|
||||
if(event->value.button.id == ButtonsLeft) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
case LayoutActionRight:
|
||||
if(event->value.button.id == ButtonsRight) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
case LayoutActionOk:
|
||||
if(event->value.button.id == ButtonsOk) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
case LayoutActionBack:
|
||||
if(event->value.button.id == ButtonsBack) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
|
||||
// stub action
|
||||
case LayoutActionUsbDisconnect:
|
||||
if(event->value.button.id == ButtonsLeft) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
|
||||
case LayoutActionUsbConnect:
|
||||
if(event->value.button.id == ButtonsRight) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
if(next) {
|
||||
printf("[layout view] go to next item\n");
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
next->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EventTypeUsb: {
|
||||
printf("get usb event\n");
|
||||
|
||||
FlipperComponent* next = NULL;
|
||||
|
||||
if(event->value.usb == UsbEventConnect) {
|
||||
for(size_t i = 0; i < this->actions_size; i++) {
|
||||
if(this->actions[i].action == LayoutActionUsbConnect) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(event->value.usb == UsbEventDisconnect) {
|
||||
for(size_t i = 0; i < this->actions_size; i++) {
|
||||
if(this->actions[i].action == LayoutActionUsbDisconnect) {
|
||||
next = this->actions[i].item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(next) {
|
||||
printf("[layout view] go to next item\n");
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
next->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
}
|
||||
} break;
|
||||
|
||||
// start component from prev
|
||||
case EventTypeUiNext:
|
||||
printf("[layout view] start component %lX\n", (uint32_t)this);
|
||||
|
||||
if(this->timeout > 0) {
|
||||
// TODO start timer
|
||||
}
|
||||
|
||||
// set current item to self
|
||||
store->current_component = this;
|
||||
|
||||
this->wait_time = 0;
|
||||
|
||||
// render layout
|
||||
this->dirty = true;
|
||||
break;
|
||||
|
||||
case EventTypeTick:
|
||||
this->wait_time += event->value.tick_delta;
|
||||
|
||||
if(this->wait_time > this->timeout) {
|
||||
for(size_t i = 0; i < this->actions_size; i++) {
|
||||
if(this->actions[i].action == LayoutActionTimeout ||
|
||||
this->actions[i].action == LayoutActionEndOfCycle
|
||||
) {
|
||||
if(this->actions[i].item != NULL) {
|
||||
printf("[layout view] go to next item\n");
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
this->actions[i].item->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this->dirty) {
|
||||
this->draw_fn(this->data, u8g2, area);
|
||||
|
||||
store->dirty_screen = true;
|
||||
|
||||
this->dirty = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void BlinkerComponent::handle(Event* event, Store* store, u8g2_t* u8g2, ScreenArea area) {
|
||||
switch(event->type) {
|
||||
// get button event
|
||||
case EventTypeButton:
|
||||
if(event->value.button.state && event->value.button.id == ButtonsBack) {
|
||||
if(this->prev && this->prev != this) {
|
||||
printf("[blinker view] go back\n");
|
||||
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
this->prev->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
|
||||
this->prev = NULL;
|
||||
|
||||
store->led = ColorBlack;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
} else {
|
||||
printf("[blinker view] no back/loop\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(event->value.button.state && event->value.button.id != ButtonsBack) {
|
||||
this->active = false;
|
||||
}
|
||||
|
||||
if(!event->value.button.state && event->value.button.id != ButtonsBack) {
|
||||
this->active = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// start component from prev
|
||||
case EventTypeUiNext:
|
||||
printf("[blinker view] start component %lX\n", (uint32_t)this);
|
||||
|
||||
if(this->prev == NULL) {
|
||||
this->prev = store->current_component;
|
||||
}
|
||||
|
||||
// set current item to self
|
||||
store->current_component = this;
|
||||
|
||||
this->dirty = true;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
break;
|
||||
|
||||
case EventTypeTick:
|
||||
if(this->active) {
|
||||
this->wait_time += event->value.tick_delta;
|
||||
|
||||
if(this->is_on) {
|
||||
if(this->wait_time > this->config.on_time) {
|
||||
this->wait_time = 0;
|
||||
this->is_on = false;
|
||||
}
|
||||
} else {
|
||||
if(this->wait_time > this->config.off_time) {
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
store->led = this->is_on ? this->config.on_color : this->config.off_color;
|
||||
} else {
|
||||
store->led = ColorBlack;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
}
|
||||
|
||||
if(this->dirty) {
|
||||
this->draw_fn(this->data, u8g2, area);
|
||||
|
||||
store->dirty_screen = true;
|
||||
|
||||
this->dirty = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
void BlinkerComponentOnBtn::handle(Event* event, Store* store, u8g2_t* u8g2, ScreenArea area) {
|
||||
switch(event->type) {
|
||||
// get button event
|
||||
case EventTypeButton:
|
||||
if(event->value.button.state && event->value.button.id == ButtonsBack) {
|
||||
if(this->prev && this->prev != this) {
|
||||
printf("[blinker view] go back\n");
|
||||
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
this->prev->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
|
||||
this->prev = NULL;
|
||||
|
||||
store->led = ColorBlack;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
} else {
|
||||
printf("[blinker view] no back/loop\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(event->value.button.state && event->value.button.id != ButtonsBack) {
|
||||
this->active = true;
|
||||
}
|
||||
|
||||
if(!event->value.button.state && event->value.button.id != ButtonsBack) {
|
||||
this->active = false;
|
||||
}
|
||||
break;
|
||||
|
||||
// start component from prev
|
||||
case EventTypeUiNext:
|
||||
printf("[blinker view] start component %lX\n", (uint32_t)this);
|
||||
|
||||
if(this->prev == NULL) {
|
||||
this->prev = store->current_component;
|
||||
}
|
||||
|
||||
// set current item to self
|
||||
store->current_component = this;
|
||||
|
||||
this->dirty = true;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
break;
|
||||
|
||||
case EventTypeTick:
|
||||
if(this->active) {
|
||||
this->wait_time += event->value.tick_delta;
|
||||
|
||||
if(this->is_on) {
|
||||
if(this->wait_time > this->config.on_time) {
|
||||
this->wait_time = 0;
|
||||
this->is_on = false;
|
||||
}
|
||||
} else {
|
||||
if(this->wait_time > this->config.off_time) {
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
store->led = this->is_on ? this->config.on_color : this->config.off_color;
|
||||
} else {
|
||||
store->led = ColorBlack;
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
}
|
||||
|
||||
if(this->dirty) {
|
||||
this->draw_fn(this->data, u8g2, area);
|
||||
|
||||
store->dirty_screen = true;
|
||||
|
||||
this->dirty = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
#define MENU_DRAW_LINES 4
|
||||
|
||||
Point draw_block(u8g2_t* u8g2, const char* text, Block layout, uint8_t x, uint8_t y) {
|
||||
u8g2_SetDrawColor(u8g2, layout.background);
|
||||
u8g2_DrawBox(u8g2,
|
||||
x + layout.margin_left,
|
||||
y + layout.margin_top,
|
||||
layout.width, layout.height
|
||||
);
|
||||
|
||||
u8g2_SetDrawColor(u8g2, layout.color);
|
||||
u8g2_SetFont(u8g2, layout.font);
|
||||
if(text != NULL) {
|
||||
u8g2_DrawStr(u8g2,
|
||||
x + layout.margin_left + layout.padding_left,
|
||||
y + layout.margin_top + layout.padding_top,
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
x: x + layout.margin_left + layout.width,
|
||||
y: y + layout.margin_top + layout.height
|
||||
};
|
||||
}
|
||||
|
||||
void draw_menu(MenuCtx* ctx, u8g2_t* u8g2, ScreenArea area) {
|
||||
// u8g2_ClearBuffer(u8g2);
|
||||
// clear area
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
u8g2_DrawBox(u8g2, area.x, area.y, area.width, area.height);
|
||||
|
||||
u8g2_SetFontMode(u8g2, 1);
|
||||
|
||||
uint8_t list_start = ctx->current - ctx->cursor;
|
||||
uint8_t list_size = ctx->size > MENU_DRAW_LINES ? MENU_DRAW_LINES : ctx->size;
|
||||
|
||||
// draw header
|
||||
/*
|
||||
Point next = draw_block(u8g2, (const char*)data->name, Block {
|
||||
width: 128,
|
||||
height: 14,
|
||||
margin_left: 0,
|
||||
margin_top: 0,
|
||||
padding_left: 4,
|
||||
padding_top: 13,
|
||||
background: 1,
|
||||
color: 0,
|
||||
font: (uint8_t*)u8g2_font_helvB14_tf,
|
||||
}, area.x, area.y);
|
||||
*/
|
||||
|
||||
Point next = {area.x, area.y};
|
||||
|
||||
for(size_t i = 0; i < list_size; i++) {
|
||||
next = draw_block(u8g2, (const char*)ctx->list[list_start + i].name, Block {
|
||||
width: 128,
|
||||
height: 15,
|
||||
margin_left: 0,
|
||||
margin_top: i == 0 ? 2 : 0,
|
||||
padding_left: 2,
|
||||
padding_top: 12,
|
||||
background: i == ctx->cursor ? 1 : 0,
|
||||
color: i == ctx->cursor ? 0 : 1,
|
||||
font: (uint8_t*)u8g2_font_7x14_tf,
|
||||
}, area.x, next.y);
|
||||
}
|
||||
|
||||
// u8g2_font_7x14_tf
|
||||
// u8g2_font_profont12_tf smallerbut cute
|
||||
// u8g2_font_samim_12_t_all орочий
|
||||
}
|
||||
|
||||
void MenuCtx::handle(MenuEvent event) {
|
||||
uint8_t menu_size = this->size > MENU_DRAW_LINES ? MENU_DRAW_LINES : this->size;
|
||||
|
||||
switch(event) {
|
||||
case MenuEventDown: {
|
||||
if(this->current < (this->size - 1)) {
|
||||
this->current++;
|
||||
|
||||
if(this->cursor < menu_size - 2 || this->current == this->size - 1) {
|
||||
this->cursor++;
|
||||
}
|
||||
} else {
|
||||
this->current = 0;
|
||||
this->cursor = 0;
|
||||
}
|
||||
} break;
|
||||
|
||||
case MenuEventUp: {
|
||||
if(this->current > 0) {
|
||||
this->current--;
|
||||
|
||||
if(this->cursor > 1 || this->current == 0) {
|
||||
this->cursor--;
|
||||
}
|
||||
|
||||
} else {
|
||||
this->current = this->size - 1;
|
||||
this->cursor = menu_size - 1;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuCtx::reset() {
|
||||
this->current = 0;
|
||||
this->cursor = 0;
|
||||
}
|
||||
|
||||
// draw numenu and handle navigation
|
||||
void MenuComponent::handle(Event* event, Store* store, u8g2_t* u8g2, ScreenArea area) {
|
||||
switch(event->type) {
|
||||
// get button event
|
||||
case EventTypeButton: {
|
||||
if(event->value.button.id == ButtonsOk && event->value.button.state) {
|
||||
if(this->ctx.current < this->ctx.size) {
|
||||
FlipperComponent* next_item = (FlipperComponent*)this->ctx.list[this->ctx.current].item;
|
||||
|
||||
if(next_item) {
|
||||
store->is_fullscreen = false;
|
||||
|
||||
printf("[layout view] go to %d item\n", this->ctx.current);
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
|
||||
next_item->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
} else {
|
||||
printf("[menu view] no item at %d\n", this->ctx.current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(event->value.button.id == ButtonsDown && event->value.button.state) {
|
||||
this->ctx.handle(MenuEventDown);
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
if(event->value.button.id == ButtonsUp && event->value.button.state) {
|
||||
this->ctx.handle(MenuEventUp);
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
// go back item
|
||||
if(event->value.button.id == ButtonsBack && event->value.button.state) {
|
||||
if(this->prev && this->prev != this) {
|
||||
store->is_fullscreen = false;
|
||||
|
||||
printf("[menu view] go back\n");
|
||||
|
||||
this->ctx.reset();
|
||||
|
||||
Event send_event;
|
||||
send_event.type = EventTypeUiNext;
|
||||
this->prev->handle(
|
||||
&send_event,
|
||||
store,
|
||||
u8g2,
|
||||
area
|
||||
);
|
||||
|
||||
this->prev = NULL;
|
||||
} else {
|
||||
printf("[menu view] no back/loop\n");
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
// start component from prev
|
||||
case EventTypeUiNext:
|
||||
printf("[menu view] start component %lX (size %d)\n", (uint32_t)this, this->ctx.size);
|
||||
|
||||
// set prev item
|
||||
if(this->prev == NULL) {
|
||||
printf("[menu view] set prev element to %lX\n", (uint32_t)store->current_component);
|
||||
this->prev = store->current_component;
|
||||
}
|
||||
// set current item to self
|
||||
store->current_component = this;
|
||||
|
||||
store->is_fullscreen = true;
|
||||
|
||||
// render menu
|
||||
this->dirty = true;
|
||||
break;
|
||||
|
||||
case EventTypeTick:
|
||||
if(this->dirty) {
|
||||
draw_menu(&this->ctx, u8g2, area);
|
||||
store->dirty_screen = true;
|
||||
this->dirty = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
218
lib/ui/ui.h
Normal file
218
lib/ui/ui.h
Normal file
@@ -0,0 +1,218 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "u8g2_support.h"
|
||||
#include "u8g2/u8g2.h"
|
||||
}
|
||||
|
||||
#include "events.h"
|
||||
|
||||
typedef struct {
|
||||
void* item;
|
||||
const char* name;
|
||||
} MenuItem;
|
||||
|
||||
#include "vendor.h"
|
||||
|
||||
typedef enum {
|
||||
LayoutActionUp,
|
||||
LayoutActionDown,
|
||||
LayoutActionLeft,
|
||||
LayoutActionRight,
|
||||
LayoutActionOk,
|
||||
LayoutActionBack,
|
||||
LayoutActionTimeout,
|
||||
LayoutActionUsbConnect,
|
||||
LayoutActionUsbDisconnect,
|
||||
LayoutActionEndOfCycle
|
||||
} LayoutAction;
|
||||
|
||||
typedef struct {
|
||||
FlipperComponent* item;
|
||||
LayoutAction action;
|
||||
} ActionItem;
|
||||
|
||||
void draw_text(const char* text, u8g2_t* u8g2, ScreenArea area);
|
||||
void draw_bitmap(const char* bitmap, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
class LayoutComponent: FlipperComponent {
|
||||
public:
|
||||
LayoutComponent(void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area), ActionItem* actions, size_t actions_size, uint32_t timeout, const char* data) {
|
||||
this->data = data;
|
||||
this->actions = actions;
|
||||
this->actions_size = actions_size;
|
||||
this->timeout = timeout;
|
||||
this->draw_fn = draw_fn;
|
||||
|
||||
this->dirty = true;
|
||||
|
||||
this->wait_time = 0;
|
||||
}
|
||||
|
||||
virtual void handle(Event* event, struct _Store* store, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
private:
|
||||
const char* data;
|
||||
ActionItem* actions;
|
||||
size_t actions_size;
|
||||
uint32_t timeout;
|
||||
|
||||
void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
uint32_t wait_time;
|
||||
|
||||
bool dirty;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t on_time;
|
||||
Color on_color;
|
||||
uint32_t off_time;
|
||||
Color off_color;
|
||||
} BlinkerComponentConfig;
|
||||
|
||||
class BlinkerComponent: FlipperComponent {
|
||||
public:
|
||||
BlinkerComponent(
|
||||
void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area),
|
||||
BlinkerComponentConfig config,
|
||||
const char* data
|
||||
) {
|
||||
this->data = data;
|
||||
this->draw_fn = draw_fn;
|
||||
this->config = config;
|
||||
|
||||
this->dirty = true;
|
||||
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
this->prev = NULL;
|
||||
}
|
||||
|
||||
virtual void handle(Event* event, struct _Store* store, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
private:
|
||||
const char* data;
|
||||
BlinkerComponentConfig config;
|
||||
|
||||
void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
uint32_t wait_time;
|
||||
|
||||
bool is_on;
|
||||
bool active;
|
||||
|
||||
bool dirty;
|
||||
FlipperComponent* prev;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t on_time;
|
||||
Color on_color;
|
||||
uint32_t off_time;
|
||||
Color off_color;
|
||||
} BlinkerComponentOnBtnConfig;
|
||||
|
||||
class BlinkerComponentOnBtn: FlipperComponent {
|
||||
public:
|
||||
BlinkerComponentOnBtn(
|
||||
void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area),
|
||||
BlinkerComponentOnBtnConfig config,
|
||||
const char* data
|
||||
) {
|
||||
this->data = data;
|
||||
this->draw_fn = draw_fn;
|
||||
this->config = config;
|
||||
|
||||
this->dirty = true;
|
||||
|
||||
this->wait_time = 0;
|
||||
this->is_on = true;
|
||||
this->active = false;
|
||||
this->prev = NULL;
|
||||
}
|
||||
|
||||
virtual void handle(Event* event, struct _Store* store, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
private:
|
||||
const char* data;
|
||||
BlinkerComponentOnBtnConfig config;
|
||||
|
||||
void (*draw_fn)(const char* text, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
uint32_t wait_time;
|
||||
|
||||
bool is_on;
|
||||
bool active;
|
||||
|
||||
bool dirty;
|
||||
FlipperComponent* prev;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
MenuEventUp,
|
||||
MenuEventDown
|
||||
} MenuEvent;
|
||||
|
||||
class MenuCtx {
|
||||
public:
|
||||
size_t size;
|
||||
size_t current;
|
||||
uint8_t cursor;
|
||||
MenuItem* list;
|
||||
|
||||
void handle(MenuEvent event);
|
||||
void reset();
|
||||
};
|
||||
|
||||
void draw_menu(MenuCtx* ctx, u8g2_t* u8g2, ScreenArea area);
|
||||
|
||||
class MenuComponent: FlipperComponent {
|
||||
public:
|
||||
MenuComponent(MenuItem* list, size_t size, const char* name) {
|
||||
this->ctx.size = size;
|
||||
this->ctx.current = 0;
|
||||
this->ctx.cursor = 0;
|
||||
|
||||
this->ctx.list = list;
|
||||
|
||||
this->name = name;
|
||||
this->prev = NULL;
|
||||
|
||||
this->dirty = true;
|
||||
}
|
||||
|
||||
|
||||
const char* name;
|
||||
FlipperComponent* prev;
|
||||
MenuCtx ctx;
|
||||
|
||||
|
||||
bool dirty;
|
||||
|
||||
virtual void handle(Event* event, struct _Store* store, u8g2_t* u8g2, ScreenArea area);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} Point;
|
||||
|
||||
typedef struct {
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
uint8_t margin_left;
|
||||
uint8_t margin_top;
|
||||
uint8_t padding_left;
|
||||
uint8_t padding_top;
|
||||
uint8_t background;
|
||||
uint8_t color;
|
||||
uint8_t* font;
|
||||
} Block;
|
||||
|
||||
Point draw_block(u8g2_t* u8g2, const char* text, Block layout, uint8_t x, uint8_t y);
|
Reference in New Issue
Block a user