issue #1005, write PBM
This commit is contained in:
parent
a2a0f97ac3
commit
717a5cfb33
|
@ -1165,6 +1165,8 @@ uint8_t u8g2_NextPage(u8g2_t *u8g2);
|
|||
void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th);
|
||||
void u8g2_UpdateDisplay(u8g2_t *u8g2);
|
||||
|
||||
void u8g2_WritePBM(u8g2_t *u8g2, void (*out)(const char *s));
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
/* u8g2_ll_hvline.c */
|
||||
|
|
|
@ -179,3 +179,11 @@ void u8g2_UpdateDisplay(u8g2_t *u8g2)
|
|||
{
|
||||
u8g2_send_buffer(u8g2);
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
|
||||
void u8g2_WritePBM(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_WritePBM(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
}
|
||||
|
|
|
@ -340,7 +340,7 @@ struct u8x8_struct
|
|||
/* i2c_address is the address for writing data to the display */
|
||||
/* usually, the lowest bit must be zero for a valid address */
|
||||
uint8_t i2c_started; /* for i2c interface */
|
||||
uint8_t device_address; /* this is the device address, replacement for U8X8_MSG_CAD_SET_DEVICE */
|
||||
uint8_t device_address; /* OBSOLETE???? - this is the device address, replacement for U8X8_MSG_CAD_SET_DEVICE */
|
||||
uint8_t utf8_state; /* number of chars which are still to scan */
|
||||
uint8_t gpio_result; /* return value from the gpio call (only for MENU keys at the moment) */
|
||||
uint8_t debounce_default_pin_state;
|
||||
|
@ -960,6 +960,7 @@ uint8_t u8x8_GetUTF8Len(u8x8_t *u8x8, const char *s);
|
|||
/* itoa procedures */
|
||||
const char *u8x8_u8toa(uint8_t v, uint8_t d);
|
||||
const char *u8x8_u16toa(uint16_t v, uint8_t d);
|
||||
const char *u8x8_utoa(uint16_t v);
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
|
@ -1000,6 +1001,12 @@ uint8_t u8x8_UserInterfaceSelectionList(u8x8_t *u8x8, const char *title, uint8_t
|
|||
/* u8x8_message.c */
|
||||
uint8_t u8x8_UserInterfaceMessage(u8x8_t *u8x8, const char *title1, const char *title2, const char *title3, const char *buttons);
|
||||
|
||||
/*==========================================*/
|
||||
/* u8x8_capture.c */
|
||||
|
||||
void u8x8_capture_WritePBM(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s));
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
|
||||
/* u8x8_input_value.c */
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
|
||||
u8x8_capture.c
|
||||
|
||||
Screen capture feature
|
||||
|
||||
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.
|
||||
|
||||
|
||||
Warning: This will use global variables
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
struct _u8x8_capture_struct
|
||||
{
|
||||
u8x8_msg_cb old_cb;
|
||||
uint8_t *buffer; /* tile_width*tile_height*8 bytes */
|
||||
uint8_t tile_width;
|
||||
uint8_t tile_height;
|
||||
};
|
||||
typedef struct _u8x8_capture_struct u8x8_capture_t;
|
||||
|
||||
/*========================================================*/
|
||||
|
||||
u8x8_capture_t u8x8_capture;
|
||||
|
||||
/*========================================================*/
|
||||
|
||||
static void u8x8_capture_memory_copy(uint8_t *dest, uint8_t *src, uint16_t cnt)
|
||||
{
|
||||
while( cnt > 0 )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
||||
static void u8x8_capture_DrawTiles(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
|
||||
{
|
||||
uint8_t *dest_ptr = capture->buffer;
|
||||
//printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
|
||||
if ( dest_ptr == NULL )
|
||||
return;
|
||||
dest_ptr += (uint16_t)ty*capture->tile_width*8;
|
||||
dest_ptr += (uint16_t)tx*8;
|
||||
u8x8_capture_memory_copy(dest_ptr, tile_ptr, tile_cnt*8);
|
||||
}
|
||||
|
||||
uint8_t u8x8_capture_GetPixel(u8x8_capture_t *capture, uint16_t x, uint16_t y)
|
||||
{
|
||||
uint8_t *dest_ptr = capture->buffer;
|
||||
if ( dest_ptr == NULL )
|
||||
return 0;
|
||||
dest_ptr += (y/8)*capture->tile_width*8;
|
||||
y &= 7;
|
||||
dest_ptr += x;
|
||||
if ( (*dest_ptr & (1<<y)) == 0 )
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void u8x8_capture_WritePBM(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_t capture;
|
||||
uint16_t x, y;
|
||||
uint16_t w, h;
|
||||
|
||||
out("P1\n");
|
||||
out(u8x8_utoa(tile_width*8));
|
||||
out("\n");
|
||||
out(u8x8_utoa(tile_height*8));
|
||||
out("\n");
|
||||
|
||||
|
||||
capture.buffer = buffer;
|
||||
capture.tile_width = tile_width;
|
||||
capture.tile_height = tile_height;
|
||||
w = tile_width;
|
||||
w *= 8;
|
||||
h = tile_height;
|
||||
h *= 8;
|
||||
|
||||
|
||||
for( y = 0; y < h; y++)
|
||||
{
|
||||
for( x = 0; x < w; x++)
|
||||
{
|
||||
if ( u8x8_capture_GetPixel(&capture, x, y) )
|
||||
out("1 ");
|
||||
else
|
||||
out("0 ");
|
||||
}
|
||||
out("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*========================================================*/
|
||||
|
||||
uint8_t u8x8_d_capture(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
if ( msg == U8X8_MSG_DISPLAY_DRAW_TILE )
|
||||
{
|
||||
uint8_t x, y, c;
|
||||
uint8_t *ptr;
|
||||
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
|
||||
y = ((u8x8_tile_t *)arg_ptr)->y_pos;
|
||||
c = ((u8x8_tile_t *)arg_ptr)->cnt;
|
||||
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
|
||||
do
|
||||
{
|
||||
u8x8_capture_DrawTiles(&u8x8_capture, x, y, c, ptr);
|
||||
x += c;
|
||||
arg_int--;
|
||||
} while( arg_int > 0 );
|
||||
}
|
||||
return u8x8_capture.old_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
}
|
||||
|
||||
uint8_t u8x8_GetCaptureMemoryPixel(u8x8_t *u8x8, uint16_t x, uint16_t y)
|
||||
{
|
||||
return u8x8_capture_GetPixel(&u8x8_capture, x, y);
|
||||
}
|
||||
|
||||
/* memory: tile_width*tile_height*8 bytes */
|
||||
void u8x8_ConnectCapture(u8x8_t *u8x8, uint8_t tile_width, uint8_t tile_height, uint8_t *memory)
|
||||
{
|
||||
if ( u8x8->display_cb == u8x8_d_capture )
|
||||
return; /* do nothing, capture already installed */
|
||||
|
||||
u8x8_capture.buffer = memory; /* tile_width*tile_height*8 bytes */
|
||||
u8x8_capture.tile_width = tile_width;
|
||||
u8x8_capture.tile_height = tile_height;
|
||||
u8x8_capture.old_cb = u8x8->display_cb;
|
||||
u8x8->display_cb = u8x8_d_capture;
|
||||
return;
|
||||
}
|
||||
|
|
@ -66,3 +66,12 @@ const char *u8x8_u16toa(uint16_t v, uint8_t d)
|
|||
return u8x8_u16toap(buf, v) + d;
|
||||
}
|
||||
|
||||
const char *u8x8_utoa(uint16_t v)
|
||||
{
|
||||
const char *s = u8x8_u16toa(v, 5);
|
||||
while( *s == '0' )
|
||||
s++;
|
||||
if ( *s == '\0' )
|
||||
s--;
|
||||
return s;
|
||||
}
|
Binary file not shown.
|
@ -2,11 +2,38 @@
|
|||
|
||||
hex2lpc.c
|
||||
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, olikraus
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. 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.
|
||||
|
||||
Upload Intel Hex File to LPC8xx devices
|
||||
|
||||
Features:
|
||||
- Calculates the checksum at 0x001c in the vector table
|
||||
- Part ID detection (if no hex file is specified on the commandline)
|
||||
- Autostart of the uploaded hex file
|
||||
|
||||
ToDo:
|
||||
Consider https://github.com/ChristianVisintin/termiWin for Win compatibility
|
||||
|
@ -34,6 +61,8 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
#define VERSION "1.0"
|
||||
|
||||
/* this defines the number of bytes, which should be sent before any further read happens */
|
||||
/* it seems that there is a echo with the LPC devices, so that all data sent to the LPC */
|
||||
/* is always sent back. This means, while writing, the same number of bytes are sent back */
|
||||
|
@ -1625,13 +1654,14 @@ int is_arg(char ***argv, int c)
|
|||
/*================================================*/
|
||||
void help(void)
|
||||
{
|
||||
printf("Version " VERSION);
|
||||
printf("-h Display this help\n");
|
||||
printf("-f <file> Load data from intel hex <file>\n");
|
||||
printf("-v Verify flash upload\n");
|
||||
printf("-x Execute ARM reset handler after upload\n");
|
||||
printf(" Note: Reset handler must set the stack pointer and restore SYSMEMREMAP\n");
|
||||
printf("-p <port> Use UART at <port> (default: '/dev/ttyUSB0')\n");
|
||||
printf("-s <n> Set UART transfer speed, 0=9600 (default), 1=19200, 2=57600, 3=115200\n");
|
||||
printf("-s <n> Set UART transfer speed, 0=9600 (default), 1=19200, 2=57600, 3=115200, 4=230400\n");
|
||||
printf("-i Show ISP commands sent to the device\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,10 @@ https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontroller
|
|||
"LPC804 Example Code Bundle MCUXpresso"
|
||||
|
||||
|
||||
the file inc/chip_setup.h might depend on then project, but should
|
||||
be a good starting point.
|
||||
|
||||
Toplevel include should be "LPC8xx.h".
|
||||
The name "LPC8xx.h" might be misleading: This file is specific to the LPC804, but
|
||||
i decided to to change the name, but keep the orginal file name from the above zip
|
||||
I decided not to change the name, but keep the orginal file name from the above zip
|
||||
folder. In fact plan is not to modify any of the files in lpc_chip_804 so that they can
|
||||
be overwritten at any time with the original files (maybe chip_setup.h is an exception).
|
||||
|
||||
|
@ -27,7 +25,7 @@ While working in the code, I saw, that there are some issues in "lpc_chip_804":
|
|||
- Alligned "unsigned int" with "uint32_t" declarations in syscon.h and .c
|
||||
- Change the inclusion of "lpc8xx.h" to "LPC8xx.h" in i2c.h
|
||||
|
||||
As a conclusion, I had to change the following files:
|
||||
As a conclusion, I had to change the following files compared to the original zip content:
|
||||
i2c.h syscon.h syscon.c i2c.c spi.c spi.h plu.c
|
||||
|
||||
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
u8g2_t u8g2;
|
||||
|
||||
void stdout_string(const char *s)
|
||||
{
|
||||
printf("%s", s);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x, y;
|
||||
|
@ -44,7 +49,7 @@ int main(void)
|
|||
u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0);
|
||||
u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0);
|
||||
|
||||
u8g2_DrawFilledEllipse(&u8g2, x, y, 23, 27, U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_LOWER_LEFT);
|
||||
//u8g2_DrawFilledEllipse(&u8g2, x, y, 23, 27, U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_LOWER_LEFT);
|
||||
|
||||
u8g2_SendBuffer(&u8g2);
|
||||
/*
|
||||
|
@ -94,6 +99,9 @@ int main(void)
|
|||
if ( k == 'd' ) x += 1;
|
||||
if ( k == 'q' ) break;
|
||||
|
||||
if ( k == 'c' )
|
||||
u8g2_WritePBM(&u8g2, stdout_string);
|
||||
|
||||
|
||||
//if ( k == 't' )
|
||||
// u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
|
||||
|
|
Loading…
Reference in New Issue