From 75843d7e163f97fd42f96661863c1de664b08cc8 Mon Sep 17 00:00:00 2001 From: Guo Wenxue <guowenxue@gmail.com> Date: Sun, 07 Jul 2024 19:28:29 +0800 Subject: [PATCH] Update modules led source code to support other pins --- modules/w25qflash.c | 128 ++++++++++++++++++------------------------ 1 files changed, 55 insertions(+), 73 deletions(-) diff --git a/modules/w25qflash.c b/modules/w25qflash.c index 345f0b6..db20abd 100644 --- a/modules/w25qflash.c +++ b/modules/w25qflash.c @@ -1,16 +1,25 @@ /********************************************************************************* - * Copyright: (C) 2023 LingYun IoT System Studio. All Rights Reserved. + * Copyright: (C) 2023 LingYun IoT System Studio + * All rights reserved. + * + * Filename: at24c.c + * Description: This file is AT24Cxx EEPROM code + * + * Version: 1.0.0(10/08/23) * Author: Guo Wenxue <guowenxue@gmail.com> + * ChangeLog: 1, Release initial version on "10/08/23 17:52:00" * - * Description: This file is W25Qxx SPI Norflash driver on RaspberryPi 40Pin. + * Pin connection: + * W25QXX Raspberry Pi 40Pin + * VCC <---> Pin#1 (3.3V) + * CS <---> Pin#24(CS) + * DO <---> Pin#21(MISO) + * GND <---> Pin#9 (GND) + * CLK <---> Pin#23(SCLK) + * DI <---> Pin#19(MOSI) * - * W25QXX RaspberryPi 40Pin - * VCC <---> 3.3V(Pin#1) - * CS <---> CS(Pin#24) - * DO <---> MISO(Pin#21) - * GND <---> GND(Pin#9) - * CLK <---> SCLK(Pin#23) - * DI <---> MOSI(Pin#19) + * /boot/config.txt: + * dtparam=spi=on * ********************************************************************************/ @@ -46,7 +55,7 @@ *| Entry Functions | *+-----------------------+*/ -void dump_buf(const char *prompt, char *buf, size_t len); +void dump_buf(const char *prompt, char *buffer, size_t length); int main (int argc, char **argv) { @@ -745,9 +754,9 @@ } while ((buf[1] & 0x01) == 0x01); } -/*+----------------+ - *| dump_buf | - *+----------------+*/ +/*+----------------------+ + *| Misc functions | + *+----------------------+*/ void print_buf(const char *prompt, uint8_t *buf, int size) { @@ -772,74 +781,47 @@ return ; } -#define LINELEN 81 -#define CHARS_PER_LINE 16 -static char *print_char = -" " -" " -" !\"#$%&'()*+,-./" -"0123456789:;<=>?" -"@ABCDEFGHIJKLMNO" -"PQRSTUVWXYZ[\\]^_" -"`abcdefghijklmno" -"pqrstuvwxyz{|}~ " -" " -" " -" ???????????????" -"????????????????" -"????????????????" -"????????????????" -"????????????????" -"????????????????"; - -void dump_buf(const char *prompt, char *buf, size_t len) +void dump_buf(const char *prompt, char *buffer, size_t length) { - int rc; - int idx; - char prn[LINELEN]; - char lit[CHARS_PER_LINE + 2]; - char hc[4]; - short line_done = 1; + size_t i, j; - if( prompt ) - printf("%s", prompt); - - rc = len; - idx = 0; - lit[CHARS_PER_LINE] = '\0'; - - while (rc > 0) + if (prompt) { - if (line_done) - snprintf(prn, LINELEN, "%08X: ", idx); - - do - { - unsigned char c = buf[idx]; - snprintf(hc, 4, "%02X ", c); - strncat(prn, hc, LINELEN); - - lit[idx % CHARS_PER_LINE] = print_char[c]; - } - while (--rc > 0 && (++idx % CHARS_PER_LINE != 0)); - - line_done = (idx % CHARS_PER_LINE) == 0; - if (line_done) - { - printf("%s %s\r\n", prn, lit); - } + printf("%s\n", prompt); } - if (!line_done) + for (i = 0; i < length; i += 16) { - int ldx = idx % CHARS_PER_LINE; - lit[ldx++] = print_char[(int)buf[idx]]; - lit[ldx] = '\0'; + printf("%08zx: ", i); - while ((++idx % CHARS_PER_LINE) != 0) - strncat(prn, " ", sizeof(prn)-strlen(prn)); + for (j = 0; j < 16; j++) + { + if (i + j < length) + { + printf("%02x ", buffer[i + j]); + } + else + { + printf(" "); + } + } - printf("%s %s\r\n", prn, lit); + printf(" "); + for (j = 0; j < 16; j++) + { + if (i + j < length) + { + unsigned char c = buffer[i + j]; + printf("%c", (c >= 32 && c <= 126) ? c : '.'); + } + else + { + printf(" "); + } + } + + printf("\n"); } } + -- Gitblit v1.9.1