diff --git a/csrc/u8g2.h b/csrc/u8g2.h index 8548366a..eb155821 100644 --- a/csrc/u8g2.h +++ b/csrc/u8g2.h @@ -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 */ diff --git a/csrc/u8g2_buffer.c b/csrc/u8g2_buffer.c index 95ca08f1..20126f02 100644 --- a/csrc/u8g2_buffer.c +++ b/csrc/u8g2_buffer.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); +} diff --git a/csrc/u8x8.h b/csrc/u8x8.h index 42054d0f..3f976fc6 100644 --- a/csrc/u8x8.h +++ b/csrc/u8x8.h @@ -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 */ diff --git a/csrc/u8x8_capture.c b/csrc/u8x8_capture.c new file mode 100644 index 00000000..11085b99 --- /dev/null +++ b/csrc/u8x8_capture.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<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; +} + diff --git a/csrc/u8x8_u16toa.c b/csrc/u8x8_u16toa.c index 8a3afb56..0cedde85 100644 --- a/csrc/u8x8_u16toa.c +++ b/csrc/u8x8_u16toa.c @@ -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; +} \ No newline at end of file diff --git a/sys/arm/lpc804/blink/blink.a b/sys/arm/lpc804/blink/blink.a deleted file mode 100644 index cb04e47c..00000000 Binary files a/sys/arm/lpc804/blink/blink.a and /dev/null differ diff --git a/sys/arm/lpc804/hex2lpc/hex2lpc.c b/sys/arm/lpc804/hex2lpc/hex2lpc.c index 4384501f..0347cce1 100644 --- a/sys/arm/lpc804/hex2lpc/hex2lpc.c +++ b/sys/arm/lpc804/hex2lpc/hex2lpc.c @@ -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 +#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 Load data from intel hex \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 Use UART at (default: '/dev/ttyUSB0')\n"); - printf("-s Set UART transfer speed, 0=9600 (default), 1=19200, 2=57600, 3=115200\n"); + printf("-s 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"); } diff --git a/sys/arm/lpc804/lpc_chip_804/info.txt b/sys/arm/lpc804/lpc_chip_804/info.txt index 7ecf98a7..c04a2e03 100644 --- a/sys/arm/lpc804/lpc_chip_804/info.txt +++ b/sys/arm/lpc804/lpc_chip_804/info.txt @@ -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 \ No newline at end of file diff --git a/sys/sdl/text_full_buffer/main.c b/sys/sdl/text_full_buffer/main.c index 6f4b8ff5..5a66d093 100644 --- a/sys/sdl/text_full_buffer/main.c +++ b/sys/sdl/text_full_buffer/main.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");