Several examples run on only mbed-os5.13.0 (not 5.14.0)
Dependencies: BD_SD_DISCO_F769NI BSP_DISCO_F769NI LCD_DISCO_F769NI TS_DISCO_F769NI USBHost_F769NI
Revision 4:0f4affc00183, committed 2019-10-14
- Comitter:
- kenjiArai
- Date:
- Mon Oct 14 08:55:15 2019 +0000
- Parent:
- 3:35ac9ee7d2d6
- Commit message:
- Several Examples
Changed in this revision
--- a/Mandelbrot/mandelbrot.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/Mandelbrot/mandelbrot.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,7 +2,9 @@ // Class for drawing Mandelbrot set // 2015/11/03, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- -// Modified by JH1PJL/K.Arai July 25th,2019 for DISCO-F769NI +// https://os.mbed.com/users/MikamiUitOpen/code/F746_Mandelbrot/ +// +// Modified by JH1PJL/K.Arai October 14th, 2019 for DISCO-F769NI #include "mandelbrot.hpp"
--- a/Mandelbrot/mandelbrot.hpp Wed Aug 07 05:39:01 2019 +0000 +++ b/Mandelbrot/mandelbrot.hpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,8 +2,10 @@ // Class for drawing Mandelbrot set -- Header // 2015/11/03, Copyright (c) 2015 MIKAMI, Naoki //----------------------------------------------------------- -// Modified by JH1PJL/K.Arai April 26th,2018 for DISCO-F469NI -// Modified by JH1PJL/K.Arai July 25th,2019 for DISCO-F769NI +// https://os.mbed.com/users/MikamiUitOpen/code/F746_Mandelbrot/ +// +// Modified by JH1PJL/K.Arai April 26th, 2018 for DISCO-F469NI +// Modified by JH1PJL/K.Arai October 14th, 2019 for DISCO-F769NI #ifndef F769_MANDELBROT_HPP #define F769_MANDELBROT_HPP
--- a/Nioi_main.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -/* - * Mbed Application program / Nioi Sensor - * - * Created: July 28th, 2019 - * Revised: August 6th, 2019 - */ - -#include "select_program.h" -#ifdef NIOI_SENSOR - -// Include -------------------------------------------------------------------- -#include <stdlib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostSerial.h" -//#include "USBHostMSD.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "mon.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define LEDON 1 -#define LEDOFF 0 - -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -struct PointF { - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -// Constructor ---------------------------------------------------------------- -LCD_DISCO_F769NI lcd; -TS_DISCO_F769NI ts; -Serial pc(SERIAL_TX, SERIAL_RX, 115200); -DigitalIn userSW(BUTTON1); -DigitalOut led_red(LED1); -DigitalOut led_green0(LED2); -DigitalOut led_green1(LED3); -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); -CircularBuffer<char, 512> rxbuf0; -CircularBuffer<char, 512> rxbuf1; - -// RAM ------------------------------------------------------------------------ -bool flag_opening_done = false; -typedef struct { - bool flag; -} mail_x_t; -Mail<mail_x_t, 2> mail_box0; -Mail<mail_x_t, 2> mail_box1; - -// ROM / Constant data -------------------------------------------------------- -const int X0 = 0; // origin of x axis -const int Y0 = 0; // origin of y axis - -const int NX = 670; // number of pixels for horizon -const int NY = 542; // number of pixels for vertical - -// Function prototypes -------------------------------------------------------- -//static void tsk_0(void const *args); -static void task_usb_serial(void const *args); -static void task_serial_out(void const *args); -static void task_show_data(void const *args); - -//extern void time_enter_mode(void); -static void goto_standby(void); - -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -extern void task_opening_action(void const *args); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -osThreadDef(task_opening_action, osPriorityNormal,4096); -osThreadDef(task_usb_serial, osPriorityNormal,4096); -osThreadDef(task_serial_out, osPriorityNormal,4096); -osThreadDef(task_show_data, osPriorityNormal,4096); - -int main() -{ - flag_opening_done = false; - osThreadId id0, id1, id2, id3; - DBG("line:%d\r\n", __LINE__); - id0 = osThreadCreate(osThread(task_opening_action), NULL); - while (flag_opening_done == false) { - DBG("line:%d\r\n", __LINE__); - ThisThread::sleep_for(100); - } - osThreadTerminate(id0); - wait_ms(100); - // - id1 = osThreadCreate(osThread(task_usb_serial), NULL); - id2 = osThreadCreate(osThread(task_serial_out), NULL); - id3 = osThreadCreate(osThread(task_show_data), NULL); - pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", - (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -void task_usb_serial(void const *args) -{ - DBG("line:%d\r\n", __LINE__); - USBHostSerial usb_ser; - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - while(true) { - DBG("line:%d\r\n", __LINE__); - // try to connect a USB serial device - while(!usb_ser.connect()) { - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - } - // in a loop, print all characters received - // if the device is disconnected, we try to connect it again - while (true) { - DBG("line:%d\r\n", __LINE__); - // if device disconnected, try to connect it again - if (!usb_ser.connected()) { - break; - } - // print characters received - while (usb_ser.available()) { - //pc.printf("%c", usb_ser.getc()); - char c = usb_ser.getc(); - rxbuf0.push(c); - rxbuf1.push(c); - if (c == '\n') { - led_red = !led_red; - mail_x_t *mail0 = mail_box0.alloc(); - mail0->flag = true; - mail_box0.put(mail0); - mail_x_t *mail1 = mail_box1.alloc(); - mail1->flag = true; - mail_box1.put(mail1); - } - } - } - } -} - -void task_serial_out(void const *args) -{ - led_green0 = 0; - rxbuf0.reset(); - while(true) { - osEvent evt = mail_box0.get(); - if (evt.status == osEventMail) { - mail_x_t *mail0 = (mail_x_t*)evt.value.p; - mail_box0.free(mail0); - while (!rxbuf0.empty()) { - char dt = 0; - rxbuf0.pop(dt); - pc.printf("%c", dt); - } - led_green0 = !led_green0; - } - } -} - -/* - 0 1 2 3 4 5 6 7 - 01234567890123456789012345678901234567890123456789012345678901234567890 - DATA,31952169,31911616,31932928,31950703,31913741,31449711,34.7,33.5 - data = 67 + 2 (\r\n) = 69 -*/ -char rcv_buf[512]; - -void task_show_data(void const *args) -{ - uint32_t n; - led_green1 = 0; - lcd.Clear(LCD_COLOR_WHITE); - lcd.SetBackColor(LCD_COLOR_WHITE); - lcd.SetTextColor(LCD_COLOR_BLACK); - lcd.DisplayStringAt(5, - LINE(1), - (uint8_t *)"Display Raw data form the sensor ", - LEFT_MODE); - rxbuf1.reset(); - while(true) { - osEvent evt = mail_box1.get(); - n = 0; - if (evt.status == osEventMail) { - mail_x_t *mail1 = (mail_x_t*)evt.value.p; - mail_box1.free(mail1); - while (!rxbuf1.empty()) { - char dt = 0; - rxbuf1.pop(dt); - pc.printf("%c", dt); - rcv_buf[n] = dt; - ++n; - } - n -= 2; - rcv_buf[n] = 0; // delete \r and \n - lcd.DisplayStringAt(10, - LINE(3), - (uint8_t *)rcv_buf, - LEFT_MODE); - //pc.printf("data length = %d, data=%s", n, rcv_buf); - led_green1 = !led_green1; - } - } -} - -void goto_standby(void) -{ - ThisThread::sleep_for(0x7fffffff); // sleep 24 days -} - -#endif
--- a/Nioi_main_copy0.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: July 30th, 2019 - */ - -//#include "select_program.h" -#if defined(NIOI_SENSOR) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define DATETIME_20190701 1561939200 // passed seconds from 1970/1/1 to 2019/7/1 - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern SDBlockDeviceDISCOF769NI bd; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; -extern TS_DISCO_F769NI ts; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void opening_action(void); -extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void time_enter_mode(void); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void opening_action(void) -{ - time_t seconds; - //char buf[64]; // data buffer for text - Timer t; - - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - pc.printf(" MBED_VERSION=%d.%d.%d\r\n", - MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); - // allocate memory to contain the whole file: - char *buf = (char*) malloc (64); - lcd.Clear(LCD_COLOR_WHITE); - pc.printf("line:%d\r\n", __LINE__); - //Mounting SD-based filesystem - int error = fs.mount(&bd); - pc.printf("line:%d\r\n", __LINE__); - if (error != 0) { - pc.printf("retrun error/Failure. %d\r\n", error); - } - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty_big.bmp", 160, 200); - pc.printf("line:%d\r\n", __LINE__); - while(true) { - ThisThread::sleep_for(1000); - } - t.reset(); - t.start(); - seconds = time(NULL); - while (seconds < DATETIME_20190701) { - lcd.SetTextColor(LCD_COLOR_BLUE); - lcd.DisplayStringAt( - 0, - 400, - (uint8_t *)"Current time is NOT correct!!", - CENTER_MODE); - lcd.DisplayStringAt( - 0, - 420, - (uint8_t *)"Plese enter the time from PC VCOM terminal.", - CENTER_MODE); - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - pc.printf("Current time is NOT correct."); - pc.printf("Please enter current date and time.\r\n"); - time_enter_mode(); - seconds = time(NULL); - } - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - uint32_t time_show = t.read(); - if (time_show < 1999) { - ThisThread::sleep_for(2000 - time_show); - } - lcd.Clear(LCD_COLOR_WHITE); - pc.printf("line:%d\r\n", __LINE__); - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty.bmp", 600, 6); - - uint32_t backColor = 0xFF006A6C; // teal green - uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button - - const string strButton[2] = {"Start measurement", "Show time"}; - ButtonGroup bGroup(lcd, ts, 200, 270, 350, 80, - LCD_COLOR_BLUE, backColor, - 2, strButton, 0, 15, 1, Font24); - pc.printf("line:%d\r\n", __LINE__); - - int32_t num = -1; - // select color pattern and display - while (num == -1) { - bGroup.GetTouchedNumber(num); - } - pc.printf("num:%d\r\n", num); - t.stop(); - //Free allocated memory - free (buf); - if (num == 0) { - return; - } else if (num == 1) { - return; - } - while(true) { - ThisThread::sleep_for(1000); - } -} - -#endif \ No newline at end of file
--- a/Nioi_main_copy1.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -/* - * Mbed Application program / Nioi Sensor - * - * Created: July 28th, 2019 - * Revised: August 1st, 2019 - */ - -//#include "select_program.h" -#ifdef NIOI_SENSOR - -// Include -------------------------------------------------------------------- -#include <stdlib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostMSD.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "mon.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define LEDON 1 -#define LEDOFF 0 - -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -struct PointF { - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -// Constructor ---------------------------------------------------------------- -LCD_DISCO_F769NI lcd; -TS_DISCO_F769NI ts; -Serial pc(SERIAL_TX, SERIAL_RX, 115200); -DigitalIn userSW(BUTTON1); -DigitalOut led_red(LED1); -DigitalOut led_green0(LED2); -DigitalOut led_green1(LED3); -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); -USBHostMSD msd; - -// RAM ------------------------------------------------------------------------ -bool flag_opening_done = false; - -// ROM / Constant data -------------------------------------------------------- -const int X0 = 0; // origin of x axis -const int Y0 = 0; // origin of y axis - -const int NX = 670; // number of pixels for horizon -const int NY = 542; // number of pixels for vertical - -// Function prototypes -------------------------------------------------------- -static void tsk_0(void const *args); -static void tsk_1(void const *args); -static void tsk_2(void const *args); -static void tsk_3(void const *args); - -//extern void time_enter_mode(void); -static void goto_standby(void); - -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -extern void task_opening_action(void const *args); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -osThreadDef(task_opening_action, osPriorityNormal,4096); -osThreadDef(tsk_1, osPriorityNormal,4096); -osThreadDef(tsk_2, osPriorityNormal,4096); -osThreadDef(tsk_3, osPriorityNormal,4096); - -int main() -{ - flag_opening_done = false; - osThreadId id0, id1, id2, id3; - DBG("line:%d\r\n", __LINE__); - id0 = osThreadCreate(osThread(task_opening_action), NULL); - while (flag_opening_done == false) { - DBG("line:%d\r\n", __LINE__); - ThisThread::sleep_for(100); - } - osThreadTerminate(id0); - // - id1 = osThreadCreate(osThread(tsk_1), NULL); - id2 = osThreadCreate(osThread(tsk_2), NULL); - id3 = osThreadCreate(osThread(tsk_3), NULL); - pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", - (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -void tsk_1(void const *args) -{ - while(true) { - led_red = LEDON; - ThisThread::sleep_for(1000); - led_red = LEDOFF; - ThisThread::sleep_for(1000); - } -} - -void tsk_2(void const *args) -{ - while(true) { - led_green0 = LEDON; - ThisThread::sleep_for(1500); - led_green0 = LEDOFF; - ThisThread::sleep_for(1500); - } -} - -void tsk_3(void const *args) -{ - while(true) { - led_green1 = LEDON; - ThisThread::sleep_for(2000); - led_green1 = LEDOFF; - ThisThread::sleep_for(2000); - } -} - -void goto_standby(void) -{ - ThisThread::sleep_for(0x7fffffff); // sleep 24 days -} - -#endif
--- a/Nioi_main_copy2.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: July 30th, 2019 - */ - -//#include "select_program.h" -#if defined(NIOI_SENSOR) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define DATETIME_20190701 1561939200 // passed seconds from 1970/1/1 to 2019/7/1 - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern SDBlockDeviceDISCOF769NI bd; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; -extern TS_DISCO_F769NI ts; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void opening_action(void); -extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void time_enter_mode(void); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void opening_action(void) -{ - time_t seconds; - //char buf[64]; // data buffer for text - Timer t; - - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - pc.printf(" MBED_VERSION=%d.%d.%d\r\n", - MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); - // allocate memory to contain the whole file: - char *buf = (char*) malloc (64); - lcd.Clear(LCD_COLOR_WHITE); - pc.printf("line:%d\r\n", __LINE__); - //Mounting SD-based filesystem - int error = fs.mount(&bd); - pc.printf("line:%d\r\n", __LINE__); - if (error != 0) { - pc.printf("retrun error/Failure. %d\r\n", error); - } - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty_big.bmp", 160, 200); - pc.printf("line:%d\r\n", __LINE__); - while(true) { - ThisThread::sleep_for(1000); - } - t.reset(); - t.start(); - seconds = time(NULL); - while (seconds < DATETIME_20190701) { - lcd.SetTextColor(LCD_COLOR_BLUE); - lcd.DisplayStringAt( - 0, - 400, - (uint8_t *)"Current time is NOT correct!!", - CENTER_MODE); - lcd.DisplayStringAt( - 0, - 420, - (uint8_t *)"Plese enter the time from PC VCOM terminal.", - CENTER_MODE); - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - pc.printf("Current time is NOT correct."); - pc.printf("Please enter current date and time.\r\n"); - time_enter_mode(); - seconds = time(NULL); - } - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - uint32_t time_show = t.read(); - if (time_show < 1999) { - ThisThread::sleep_for(2000 - time_show); - } - lcd.Clear(LCD_COLOR_WHITE); - pc.printf("line:%d\r\n", __LINE__); - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty.bmp", 600, 6); - - uint32_t backColor = 0xFF006A6C; // teal green - uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button - - const string strButton[2] = {"Start measurement", "Show time"}; - ButtonGroup bGroup(lcd, ts, 200, 270, 350, 80, - LCD_COLOR_BLUE, backColor, - 2, strButton, 0, 15, 1, Font24); - pc.printf("line:%d\r\n", __LINE__); - - int32_t num = -1; - // select color pattern and display - while (num == -1) { - bGroup.GetTouchedNumber(num); - } - pc.printf("num:%d\r\n", num); - t.stop(); - //Free allocated memory - free (buf); - if (num == 0) { - return; - } else if (num == 1) { - return; - } - while(true) { - ThisThread::sleep_for(1000); - } -} - -#endif \ No newline at end of file
--- a/Nioi_main_copy3.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - * Mbed Application program / Nioi Sensor - * - * Created: July 28th, 2019 - * Revised: August 6th, 2019 - */ - -//#include "select_program.h" -#ifdef NIOI_SENSOR - -// Include -------------------------------------------------------------------- -#include <stdlib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostSerial.h" -//#include "USBHostMSD.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "mon.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define LEDON 1 -#define LEDOFF 0 - -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -struct PointF { - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -// Constructor ---------------------------------------------------------------- -LCD_DISCO_F769NI lcd; -TS_DISCO_F769NI ts; -Serial pc(SERIAL_TX, SERIAL_RX, 115200); -DigitalIn userSW(BUTTON1); -DigitalOut led_red(LED1); -DigitalOut led_green0(LED2); -DigitalOut led_green1(LED3); -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); -//USBHostMSD msd; -//USBHostSerial usb_ser; - -// RAM ------------------------------------------------------------------------ -bool flag_opening_done = false; - -// ROM / Constant data -------------------------------------------------------- -const int X0 = 0; // origin of x axis -const int Y0 = 0; // origin of y axis - -const int NX = 670; // number of pixels for horizon -const int NY = 542; // number of pixels for vertical - -// Function prototypes -------------------------------------------------------- -//static void tsk_0(void const *args); -static void task_usb_serial(void const *args); -static void tsk_2(void const *args); -static void tsk_3(void const *args); - -//extern void time_enter_mode(void); -static void goto_standby(void); - -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -extern void task_opening_action(void const *args); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -osThreadDef(task_opening_action, osPriorityNormal,4096); -osThreadDef(task_usb_serial, osPriorityNormal,4096); -osThreadDef(tsk_2, osPriorityNormal,4096); -osThreadDef(tsk_3, osPriorityNormal,4096); - -int main() -{ - flag_opening_done = false; - osThreadId id0, id1, id2, id3; - DBG("line:%d\r\n", __LINE__); - id0 = osThreadCreate(osThread(task_opening_action), NULL); - while (flag_opening_done == false) { - DBG("line:%d\r\n", __LINE__); - ThisThread::sleep_for(100); - } - osThreadTerminate(id0); - wait_ms(100); - // - id1 = osThreadCreate(osThread(task_usb_serial), NULL); - id2 = osThreadCreate(osThread(tsk_2), NULL); - id3 = osThreadCreate(osThread(tsk_3), NULL); - pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", - (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -void task_usb_serial(void const *args) -{ - DBG("line:%d\r\n", __LINE__); - USBHostSerial usb_ser; - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - while(true) { - DBG("line:%d\r\n", __LINE__); - // try to connect a USB serial device - while(!usb_ser.connect()) { - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - } - // in a loop, print all characters received - // if the device is disconnected, we try to connect it again - while (true) { - DBG("line:%d\r\n", __LINE__); - // if device disconnected, try to connect it again - if (!usb_ser.connected()) { - break; - } - // print characters received - while (usb_ser.available()) { - pc.printf("%c", usb_ser.getc()); - } - } - } -} - -void tsk_2(void const *args) -{ - while(true) { - led_green0 = LEDON; - ThisThread::sleep_for(1500); - led_green0 = LEDOFF; - ThisThread::sleep_for(1500); - } -} - -void tsk_3(void const *args) -{ - while(true) { - led_green1 = LEDON; - ThisThread::sleep_for(2000); - led_green1 = LEDOFF; - ThisThread::sleep_for(2000); - } -} - -void goto_standby(void) -{ - ThisThread::sleep_for(0x7fffffff); // sleep 24 days -} - -#endif
--- a/Nioi_main_copy4.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -/* - * Mbed Application program / Nioi Sensor - * - * Created: July 28th, 2019 - * Revised: August 6th, 2019 - */ - -//#include "select_program.h" -#ifdef NIOI_SENSOR - -// Include -------------------------------------------------------------------- -#include <stdlib.h> -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostSerial.h" -//#include "USBHostMSD.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "mon.h" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; - -#define LEDON 1 -#define LEDOFF 0 - -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -struct PointF { - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -// Constructor ---------------------------------------------------------------- -LCD_DISCO_F769NI lcd; -TS_DISCO_F769NI ts; -Serial pc(SERIAL_TX, SERIAL_RX, 115200); -DigitalIn userSW(BUTTON1); -DigitalOut led_red(LED1); -DigitalOut led_green0(LED2); -DigitalOut led_green1(LED3); -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); -CircularBuffer<char, 512> rxbuf0; -CircularBuffer<char, 512> rxbuf1; - -// RAM ------------------------------------------------------------------------ -bool flag_opening_done = false; -typedef struct { - bool flag; -} mail_x_t; -Mail<mail_x_t, 2> mail_box0; -Mail<mail_x_t, 2> mail_box1; - -// ROM / Constant data -------------------------------------------------------- -const int X0 = 0; // origin of x axis -const int Y0 = 0; // origin of y axis - -const int NX = 670; // number of pixels for horizon -const int NY = 542; // number of pixels for vertical - -// Function prototypes -------------------------------------------------------- -//static void tsk_0(void const *args); -static void task_usb_serial(void const *args); -static void task_serial_out(void const *args); -static void task_show_data(void const *args); - -//extern void time_enter_mode(void); -static void goto_standby(void); - -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -extern void task_opening_action(void const *args); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -osThreadDef(task_opening_action, osPriorityNormal,4096); -osThreadDef(task_usb_serial, osPriorityNormal,4096); -osThreadDef(task_serial_out, osPriorityNormal,4096); -osThreadDef(task_show_data, osPriorityNormal,4096); - -int main() -{ - flag_opening_done = false; - osThreadId id0, id1, id2, id3; - DBG("line:%d\r\n", __LINE__); - id0 = osThreadCreate(osThread(task_opening_action), NULL); - while (flag_opening_done == false) { - DBG("line:%d\r\n", __LINE__); - ThisThread::sleep_for(100); - } - osThreadTerminate(id0); - wait_ms(100); - // - id1 = osThreadCreate(osThread(task_usb_serial), NULL); - id2 = osThreadCreate(osThread(task_serial_out), NULL); - id3 = osThreadCreate(osThread(task_show_data), NULL); - pc.printf("id0=0x%x, id1=0x%x, id2=0x%x, id3=0x%x\r\n", - (uint32_t)id0, (uint32_t)id1, (uint32_t)id2, (uint32_t)id3); - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -void task_usb_serial(void const *args) -{ - DBG("line:%d\r\n", __LINE__); - USBHostSerial usb_ser; - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - while(true) { - DBG("line:%d\r\n", __LINE__); - // try to connect a USB serial device - while(!usb_ser.connect()) { - DBG("line:%d\r\n", __LINE__); - wait_ms(500); - } - // in a loop, print all characters received - // if the device is disconnected, we try to connect it again - while (true) { - DBG("line:%d\r\n", __LINE__); - // if device disconnected, try to connect it again - if (!usb_ser.connected()) { - break; - } - // print characters received - while (usb_ser.available()) { - //pc.printf("%c", usb_ser.getc()); - char c = usb_ser.getc(); - rxbuf0.push(c); - rxbuf1.push(c); - if (c == '\n') { - led_red = !led_red; - mail_x_t *mail0 = mail_box0.alloc(); - mail0->flag = true; - mail_box0.put(mail0); - mail_x_t *mail1 = mail_box1.alloc(); - mail1->flag = true; - mail_box1.put(mail1); - } - } - } - } -} - -void task_serial_out(void const *args) -{ - led_green0 = 0; - rxbuf0.reset(); - while(true) { - osEvent evt = mail_box0.get(); - if (evt.status == osEventMail) { - mail_x_t *mail0 = (mail_x_t*)evt.value.p; - mail_box0.free(mail0); - while (!rxbuf0.empty()) { - char dt = 0; - rxbuf0.pop(dt); - pc.printf("%c", dt); - } - led_green0 = !led_green0; - } - } -} - -/* - 0 1 2 3 4 5 6 7 - 01234567890123456789012345678901234567890123456789012345678901234567890 - DATA,31952169,31911616,31932928,31950703,31913741,31449711,34.7,33.5 - data = 67 + 2 (\r\n) = 69 -*/ -char rcv_buf[512]; - -void task_show_data(void const *args) -{ - uint32_t n; - led_green1 = 0; - lcd.Clear(LCD_COLOR_WHITE); - lcd.SetBackColor(LCD_COLOR_WHITE); - lcd.SetTextColor(LCD_COLOR_BLACK); - lcd.DisplayStringAt(5, - LINE(1), - (uint8_t *)"Display Raw data form the sensor ", - LEFT_MODE); - rxbuf1.reset(); - while(true) { - osEvent evt = mail_box1.get(); - n = 0; - if (evt.status == osEventMail) { - mail_x_t *mail1 = (mail_x_t*)evt.value.p; - mail_box1.free(mail1); - while (!rxbuf1.empty()) { - char dt = 0; - rxbuf1.pop(dt); - pc.printf("%c", dt); - rcv_buf[n] = dt; - ++n; - } - n -= 2; - rcv_buf[n] = 0; // delete \r and \n - lcd.DisplayStringAt(10, - LINE(3), - (uint8_t *)rcv_buf, - LEFT_MODE); - //pc.printf("data length = %d, data=%s", n, rcv_buf); - led_green1 = !led_green1; - } - } -} - -void goto_standby(void) -{ - ThisThread::sleep_for(0x7fffffff); // sleep 24 days -} - -#endif
--- a/check_revision.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/check_revision.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -5,11 +5,33 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * https://os.mbed.com/users/kenjiArai/ * Created: July 17th, 2019 - * Revised: August 2nd, 2019 + * Revised: October 14th, 2019 */ #include "mbed.h" +#if 0 // as of Oct.14th, Latest revision does not work for DISCO-F769 +// #1 RTC -> NG -> pc.readable() does not work +// #2 LCD -> NG -> LCD screen is not stable +// #3 Tiuch -> NG -> LCD screen is not stable +// #4 & beyond -> Gave up for checking + +// RUN ONLY ON mbed-os5.14.0 +#if (MBED_MAJOR_VERSION == 5) &&\ + (MBED_MINOR_VERSION == 14) &&\ + (MBED_PATCH_VERSION == 0) + #if defined(TARGET_STM32F769NI) + // correct mbed-os version + #else + #error "Not DISCO-F769NI" + #endif +#else + //#warning "Please use Mbed-os5.14.0" + #error "Please use Mbed-os5.14.0" +#endif + +#else // Only works well this revision + // RUN ONLY ON mbed-os5.13.0 #if (MBED_MAJOR_VERSION == 5) &&\ (MBED_MINOR_VERSION == 13) &&\ @@ -17,9 +39,11 @@ #if defined(TARGET_STM32F769NI) // correct mbed-os version #else - #error "DISCO-F769NI" + #error "Not DISCO-F769NI" #endif #else //#warning "Please use Mbed-os5.13.0" - #error "Please use Mbed-os5.13.0" + #error "Please use Mbed-os5.13.0(7482462434 25 Jun 2019 Martin Kojtal)" +#endif + #endif \ No newline at end of file
--- a/select_program.h Wed Aug 07 05:39:01 2019 +0000 +++ b/select_program.h Mon Oct 14 08:55:15 2019 +0000 @@ -5,13 +5,13 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * https://os.mbed.com/users/kenjiArai/ * Created: July 17th, 2019 - * Revised: July 29th, 2019 + * Revised: October 14th, 2019 */ /* You can select several programs. */ -#define EXAMPLE_NUMBER 99 // select 0 to 10, 99 is special function +#define EXAMPLE_NUMBER 7 // select 0 to 7 //----------------- You don't need any modification ---------------------------- #if EXAMPLE_NUMBER == 0 @@ -50,28 +50,10 @@ #warning "Compile 6_USBHost_serial.cpp" #endif #elif EXAMPLE_NUMBER == 7 - #define EXAMPLE_7_USB_MSD - #ifdef EXAMPLE_7_USB_MSD - #warning "Compile 7_USBMemory.cpp" - #error "Under development!! 7_USBMemory.cpp" - #endif -#elif EXAMPLE_NUMBER == 8 - #define EXAMPLE_8_AUDIO - #ifdef EXAMPLE_8_AUDIO - #warning "Compile 8_audio.cpp" + #define EXAMPLE_7_MANDEL + #ifdef EXAMPLE_7_MANDEL + #warning "Compile 8_Mandelbrot.cpp" #endif -#elif EXAMPLE_NUMBER == 9 - #define EXAMPLE_9_MANDEL - #ifdef EXAMPLE_9_MANDEL - #warning "Compile 9_Mandelbrot.cpp" - #endif -#elif EXAMPLE_NUMBER == 10 - #define EXAMPLE_10_BITMAP - #ifdef EXAMPLE_10_BITMAP - #warning "Compile 10_DrawBitmap.cpp" - #endif -#elif EXAMPLE_NUMBER == 99 - #define NIOI_SENSOR #else #error " Please set 0 to 5 number for EXAMPLE_NUMBER!!" #endif
--- a/z_example/0_led_blinky.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/0_led_blinky.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -5,7 +5,7 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * https://os.mbed.com/users/kenjiArai/ * Created: April 10th, 2018 - * Revised: July 18th, 2019 + * Revised: October 14th, 2019 */ #include "select_program.h" @@ -40,15 +40,16 @@ //------------------------------------------------------------------------------ // Control Program //------------------------------------------------------------------------------ -osThreadDef(tsk_0, osPriorityNormal,2048); -osThreadDef(tsk_1, osPriorityNormal,2048); -osThreadDef(tsk_2, osPriorityNormal,2048); -osThreadDef(tsk_3, osPriorityNormal,2048); +osThreadDef(tsk_0, osPriorityNormal,1024); +osThreadDef(tsk_1, osPriorityNormal,1024); +osThreadDef(tsk_2, osPriorityNormal,1024); +osThreadDef(tsk_3, osPriorityNormal,1024); int main() { pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); + printf(" LED BLINKY EXAMPLE FOR DISCO-F769NI:\r\n"); osThreadId id0, id1, id2, id3; id0 = osThreadCreate(osThread(tsk_0), NULL); id1 = osThreadCreate(osThread(tsk_1), NULL);
--- a/z_example/10_DrawBitmap.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Mbed Application program - * SD Card file control function with FatFs on Mbed-os5 - * - * Copyright (c) 2018,'19 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * https://os.mbed.com/users/kenjiArai/ - * Created: April 7th, 2018 - * Revised: July 25th, 2019 - */ - -/* - https://os.mbed.com/users/Lightsource/code/DISCO-F746NG_BMP_FROM_SDCARD/ - https://www.gimp.org/downloads/ - https://os.mbed.com/questions/69098/how-can-I-load-an-image-to-screen/#answer14107 - */ - -#include "select_program.h" -//#define EXAMPLE_10_BITMAP -#ifdef EXAMPLE_10_BITMAP - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "mon.h" -#include <stdlib.h> -#include <stdio.h> -#include <string> -#include <errno.h> - -// Definition ----------------------------------------------------------------- -#define USER_SW_ON 1 - -// Constructor ---------------------------------------------------------------- -DigitalOut myled(LED1); -DigitalIn user_sw(USER_BUTTON); -Serial pc(USBTX, USBRX, 115200); -LCD_DISCO_F769NI lcd; -// Instantiate the Block Device for sd card on DISCO-F769NI -SDBlockDeviceDISCOF769NI bd; -FATFileSystem fs("fs"); - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void drawImage(const char * name, uint16_t x, uint16_t y); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -int main() -{ - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - lcd.Clear(LCD_COLOR_WHITE); - //Mounting SD-based filesystem - int error = fs.mount(&bd); - if (error != 0) { - pc.printf("retrun error/Failure. %d\r\n", error); - } - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty_big.bmp", 160, 200); - wait(10.0f); - lcd.Clear(LCD_COLOR_WHITE); - drawImage("/fs/bmp/ty.bmp", 50, 100); - drawImage("/fs/bmp/ty.bmp", 520, 350); - drawImage("/fs/bmp/nissan0.bmp", 0, 215); - drawImage("/fs/bmp/minion480x272.bmp", 300, 0); - mon(); -} - -#endif
--- a/z_example/1_rtc.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/1_rtc.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -5,7 +5,7 @@ * http://www.page.sannet.ne.jp/kenjia/index.html * https://os.mbed.com/users/kenjiArai/ * Created: August 11th, 2017 - * Revised: July 30th, 2019 + * Revised: October 14th, 2019 */ #include "select_program.h" @@ -16,10 +16,11 @@ #include "mbed.h" // Definition ----------------------------------------------------------------- +#define USER_SW_ON 1 // Constructor ---------------------------------------------------------------- DigitalIn userSW(BUTTON1); -DigitalOut myled(LED1); // Indicate the sampling period +DigitalOut myled(LED1); // Indicate the sampling period Serial pc(USBTX, USBRX, 115200); // RAM ------------------------------------------------------------------------ @@ -30,14 +31,12 @@ const char * msg2 = "\r\nEnter Standby Mode, please push RESET to wake-up\r\n"; // Function prototypes -------------------------------------------------------- -extern void time_enter_mode(void); static void goto_standby(void); -#if 0 static void time_enter_mode(void); static void chk_and_set_time(char *ptr); static int xatoi (char **str, unsigned long *res); static void get_line (char *buff, int len); -#endif + //------------------------------------------------------------------------------ // Control Program //------------------------------------------------------------------------------ @@ -49,6 +48,7 @@ pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); + printf(" RTC EXAMPLE FOR DISCO-F769NI:\r\n"); myled = !myled; ThisThread::sleep_for(1000); myled = !myled; @@ -62,11 +62,11 @@ pc.printf("%s\r", msg1); wait_counter = 0; while (seconds == time(NULL)) { - if (pc.readable() == 1) { + if (pc.readable()) { buf[0] = pc.getc(); // dummy read time_enter_mode(); } - if (userSW == 1) { + if (userSW == USER_SW_ON) { pc.printf("%s", msg2); ThisThread::sleep_for(1000); myled = 0; @@ -91,14 +91,13 @@ ThisThread::sleep_for(0x7fffffff); // sleep 24 days } -#if 0 void time_enter_mode(void) { char *ptr; char linebuf[64]; pc.printf("\r\nSet time into RTC\r\n"); - pc.printf(" e.g. >19 7 15 10 11 12 -> July 15th,'19, 10:11:12\r\n"); + pc.printf(" e.g. >19 10 14 10 11 12 -> October 14th,'19, 10:11:12\r\n"); pc.printf(" If time is fine, just hit enter\r\n"); pc.putc('>'); ptr = linebuf; @@ -165,7 +164,8 @@ set_time(seconds); pc.printf( "Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, + t.tm_hour, t.tm_min, t.tm_sec ); } @@ -233,6 +233,5 @@ *res = val; return 1; } -#endif #endif
--- a/z_example/2_lcd.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/2_lcd.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,7 +2,7 @@ // https://os.mbed.com/teams/ST/code/DISCO-F769NI_LCD_demo/ // // Modified by K.Arai -// July 18th, 2019 +// October 14th, 2019 // #include "select_program.h" @@ -28,6 +28,7 @@ pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); + printf(" LCD EXAMPLE FOR DISCO-F769NI:\r\n"); lcd.Clear(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(++line), @@ -60,7 +61,7 @@ LINE(line += 4), (uint8_t *)buf, LEFT_MODE); - sprintf(buf, "%s %s", __DATE__, __TIME__); + sprintf(buf, "%s %s (UTC)", __DATE__, __TIME__); lcd.DisplayStringAt(20, LINE(++line), (uint8_t *)buf,
--- a/z_example/3_lcd_touch.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/3_lcd_touch.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,7 +2,7 @@ // https://os.mbed.com/teams/ST/code/DISCO-F769NI_TOUCHSCREEN_demo/ // // Modified by K.Arai -// July 18th, 2019 +// October 14th, 2019 // #include "select_program.h" @@ -23,7 +23,7 @@ pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); - printf("TOUCHSCREEN EXAMPLE FOR DISCO-F769NI START:\r\n"); + printf(" TOUCHSCREEN EXAMPLE FOR DISCO-F769NI:\r\n"); BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
--- a/z_example/4_microSD.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/4_microSD.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,11 +2,11 @@ * Mbed Application program * SD Card file control function with FatFs on Mbed-os5 * - * Copyright (c) 2018 Kenji Arai / JH1PJL + * Copyright (c) 2018,'19 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * https://os.mbed.com/users/kenjiArai/ * Created: April 7th, 2018 - * Revised: July 21st, 2019 + * Revised: October 14th, 2019 */ #include "select_program.h" @@ -18,9 +18,6 @@ #include "FATFileSystem.h" #include "SDBlockDeviceDISCOF769NI.h" #include "mon.h" -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> // Definition ----------------------------------------------------------------- #define USER_SW_ON 1 @@ -36,8 +33,8 @@ // RAM ------------------------------------------------------------------------ // ROM / Constant data -------------------------------------------------------- -char *const opening_msg0 = "microSD Card test program"; -char *const opening_msg1 = " -> run on Mbed OS-5\r\n"; +const char * opening_msg0 = "microSD Card test program"; +const char * opening_msg1 = " -> run on Mbed OS-5\r\n"; // Function prototypes -------------------------------------------------------- void return_error (int ret_val); @@ -56,9 +53,10 @@ uint32_t data4 = 50000U; uint32_t data5 = 60000U; - if (user_sw == USER_SW_ON) { - mon(); - } + pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", + __FILE__, __DATE__, __TIME__); + printf(" microSD FOR DISCO-F769NI:\r\n"); + //pc.printf("line:%d\r\n", __LINE__); pc.printf("\r\nStart\r\n"); int error = 0; @@ -67,6 +65,10 @@ error = fs.mount(&bd); return_error(error); + if (user_sw == USER_SW_ON) { + mon(); + } + FILE* fp = fopen("/fs/mydata.txt", "a"); errno_error(fp); if (fp != 0) { @@ -92,7 +94,7 @@ char tmp[64]; seconds = time(NULL); strftime(tmp, 64, "DATE %H:%M:%S,%Y/%m/%d,", localtime(&seconds)); - pc.printf(tmp); + pc.printf("%s", tmp); fprintf(fp, "%s", tmp); pc.printf("%08d;%08d;%08d;%08d;%08d;%08d\r\n", ++data0, ++data1, ++data2, ++data3, ++data4, ++data5); @@ -114,7 +116,7 @@ system_reset(); } } - Thread::wait(100); + ThisThread::sleep_for(100); if (user_sw == USER_SW_ON) { break; }
--- a/z_example/5_tcp_server.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/5_tcp_server.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,7 +2,7 @@ // https://os.mbed.com/teams/ST/code/mbed-os-tcp-server-example/ // // Modified by K.Arai -// July 17th, 2019 +// October 14th, 2019 // #include "select_program.h" @@ -39,7 +39,9 @@ int main() { - printf("Basic HTTP server example\r\n"); + pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", + __FILE__, __DATE__, __TIME__); + printf(" Basic HTTP server example for DISCO-F769NI:\r\n"); EthernetInterface eth; eth.connect();
--- a/z_example/6_USBHost_serial.cpp Wed Aug 07 05:39:01 2019 +0000 +++ b/z_example/6_USBHost_serial.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -2,7 +2,7 @@ // https://os.mbed.com/handbook/USBHostSerial // // Modified by K.Arai -// July 25th, 2019 +// October 14th, 2019 // #include "select_program.h" @@ -15,12 +15,10 @@ // Definition ----------------------------------------------------------------- - // Constructor ---------------------------------------------------------------- DigitalOut led(LED1); Serial pc(USBTX, USBRX, 115200); - // RAM ------------------------------------------------------------------------ // ROM / Constant data -------------------------------------------------------- @@ -37,6 +35,7 @@ { pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", __FILE__, __DATE__, __TIME__); + printf(" USB HOST serial for DISCO-F769NI:\r\n"); osThreadCreate(osThread(serial_task), NULL); while(true) { led=!led;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/z_example/7_Mandelbrot.cpp Mon Oct 14 08:55:15 2019 +0000 @@ -0,0 +1,176 @@ +//--------------------------------------------------------------- +// Mandelbrot set generator +// +// Mandelbrot set is displayed using 3 kinds of color pattern. +// Tap the Mandelbrot set on the screen, expanded figure by a +// factor of two around the tapped position is displayed. +// +// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki +//--------------------------------------------------------------- +// https://os.mbed.com/users/MikamiUitOpen/code/F746_Mandelbrot/ +// +// Modified by JH1PJL/K.Arai April 26th, 2018 for DISCO-F469NI +// Modified by JH1PJL/K.Arai October 14th, 2019 for DISCO-F769NI + +#include "select_program.h" +//#define EXAMPLE_7_MANDEL +#ifdef EXAMPLE_7_MANDEL + +#include "button_group.hpp" +#include "mandelbrot.hpp" + +using namespace Mikami; + +struct PointF +{ + PointF() {} + PointF(float x0, float y0) : x(x0), y(y0) {} + float x, y; +}; + +TS_DISCO_F769NI ts_; +LCD_DISCO_F769NI lcd_; +Serial pc(USBTX, USBRX, 115200); + +const int X0_ = 0; // origin of x axis +const int Y0_ = 0; // origin of y axis + +const int NX_ = 670; // number of pixels for horizon +const int NY_ = 542; // number of pixels for vertical + +void Redraw(MandelbrotBase *mandel, + float wH, float hH, PointF xy, int level, + float &x1, float &x2, float &y1, float &y2) +{ + x1 = xy.x - wH; + x2 = xy.x + wH; + y1 = xy.y - hH; + y2 = xy.y + hH; + + char str[16]; + lcd_.SetTextColor(LCD_COLOR_WHITE); + lcd_.DisplayStringAt(520, 424, (uint8_t *)str, LEFT_MODE); + sprintf(str, "x:%7.3f", xy.x); + lcd_.DisplayStringAt(520, 440, (uint8_t *)str, LEFT_MODE); + sprintf(str, "y:%7.3f", -xy.y); + lcd_.DisplayStringAt(520, 456, (uint8_t *)str, LEFT_MODE); + mandel->Display(x1, x2, y1, y2); +} + +int main() +{ + const int LEVEL = 18; + PointF xy[LEVEL]; // corresponding to touched position + + uint32_t backColor = 0xFF006A6C; // teal green + uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button + + // region to be displayed + float x1 = -2.3f; + float x2 = 0.9f; + float y1 = -1.3f; + float y2 = 1.3f; + + float wH = (x2 - x1)/2.0f; // half width of region + float hH = (y2 - y1)/2.0f; // half height of region + + xy[0] = PointF(x1 + wH, y1 + hH); + + pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", + __FILE__, __DATE__, __TIME__); + printf(" Mandelbrot picture for DISCO-F769NI:\r\n"); + + lcd_.Clear(backColor); + + MandelbrotBase *mandel[3]; + mandel[0] = new MandelbrotBW(lcd_, X0_, Y0_, NX_, NY_- 60); + mandel[1] = new MandelbrotColor1(lcd_, X0_, Y0_, NX_, NY_- 60); + mandel[2] = new MandelbrotColor2(lcd_, X0_, Y0_, NX_, NY_- 60); + + const string strButton[3] = {"B & W", "Color1", "Color2"}; + ButtonGroup bGroup(lcd_, ts_, 680, Y0_, 120, 80, + LCD_COLOR_BLUE, backColor, + 3, strButton, 0, 5, 1, Font24); + Button back(lcd_, ts_, 680, 390+Y0_, 120, 80, + LCD_COLOR_BLUE, backColor, "Back", Font24); + back.Draw(inActive, LCD_COLOR_GRAY); + + + // area of Mandelbrot set + Button area(lcd_, ts_, X0_, Y0_, NX_, NY_, backColor, backColor); + + lcd_.SetTextColor(LCD_COLOR_WHITE); + lcd_.SetFont(&Font24); + lcd_.DisplayStringAt(280, 460, (uint8_t *)"Mandelbrot set", LEFT_MODE); + + int pattern = -1; + int level = 0; + bool first = true; + while (true){ + int num = -1; + // select color pattern and display + if (bGroup.GetTouchedNumber(num) && (pattern != num)){ + bGroup.Draw(num, LCD_COLOR_DARKBLUE); + mandel[num]->Display(x1, x2, y1, y2); + pattern = num; + bGroup.Redraw(num); + + if (first){ + lcd_.SetBackColor(backColor); + lcd_.SetFont(&Font20); + lcd_.DisplayStringAt(680, LINE(16), (uint8_t *)"Tap to", + LEFT_MODE); + lcd_.DisplayStringAt(680, LINE(17), (uint8_t *)"Zoom in.", + LEFT_MODE); + first = false; + } + } + + // expand twice around tapped point + if (area.Touched() && (pattern != -1)){ + TS_StateTypeDef state = Button::GottenState(); + + uint16_t x = state.touchX[0] - X0_; + uint16_t y = state.touchY[0] - Y0_; + + lcd_.SetBackColor(backColor); + if (++level < LEVEL){ + xy[level] = PointF(mandel[pattern]->Fx(x), + mandel[pattern]->Fy(y)); + wH = wH/2.0f; + hH = hH/2.0f; + + Redraw(mandel[pattern], wH, hH, + xy[level], level, x1, x2, y1, y2); + } else { + lcd_.SetFont(&Font24); + lcd_.DisplayStringAt(X0_+76, 260, + (uint8_t *)" No more expand! ", + LEFT_MODE); + level = LEVEL - 1 ; + } + back.Redraw(); + } + + // "Back" button tapped + if (back.Touched() && level > 0){ + back.Draw(LCD_COLOR_DARKBLUE); + lcd_.SetBackColor(backColor); + if (level > 0){ + level--; + wH = wH*2.0f; + hH = hH*2.0f; + + Redraw(mandel[pattern], wH, hH, xy[level], + level, x1, x2, y1, y2); + if (level > 0){ + back.Redraw(); + } else { + back.Draw(inActive, LCD_COLOR_GRAY); + } + } + } + ThisThread::sleep_for(100); + } +} +#endif
--- a/z_example/7_USBMemory.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -// Original -// https://os.mbed.com/users/jeonbc/code/stm32-disco-example/ -// -// Modified by K.Arai -// July 25th, 2019 -// - -#include "select_program.h" -//#define EXAMPLE_7_USB_MSD -#ifdef EXAMPLE_7_USB_MSD - -#include <stdlib.h> - -#include "mbed.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostMSD.h" -#include "FATFileSystem.h" - -LCD_DISCO_F769NI lcd; - -DigitalOut led_green(LED1); -DigitalOut led_orange(LED2); -DigitalOut led_red(LED3); -DigitalOut led_blue(LED4); - -Serial pc(SERIAL_TX, SERIAL_RX, 115200); - -USBHostMSD msd; - -void msd_task(void const *) -{ - FATFileSystem fsu("usb"); - FILE *fp; - bool usb_memory_run = false; - uint32_t n = 0; - - wait(1.0f); - pc.printf("line:%d\r\n", __LINE__); - while(!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - wait_ms(20); - } - pc.printf("line:%d\r\n", __LINE__); - wait(1.0f); - if (msd.connected() == true) { - pc.printf("line:%d\r\n", __LINE__); - wait(1.0f); - if (fsu.mount(&msd) == 0) { - wait(1.0f); - usb_memory_run = true; - pc.printf("line:%d\r\n", __LINE__); - fp = fopen("test1.txt", "a"); - if (fp != 0) { - pc.printf("USBdisk:open test1.txt\r\n"); - usb_memory_run = true; - } else { - pc.printf("Cannot use USB memory\r\n"); - usb_memory_run = false; - } - fclose(fp); - } else { - pc.printf("line:%d\r\n", __LINE__); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - while (true) { - pc.printf("line:%d\r\n", __LINE__); - while(msd.connected() == false) { - while(!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - wait_ms(20); - } - pc.printf("line:%d\r\n", __LINE__); - } - if (msd.connected() == true) { - pc.printf("line:%d\r\n", __LINE__); - usb_memory_run = true; - if (fsu.mount(&msd) == 0) { - pc.printf("line:%d\r\n", __LINE__); - } else { - pc.printf("line:%d\r\n", __LINE__); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - fp = fopen("test1.txt", "a"); - pc.printf("line:%d\r\n", __LINE__); - if(fp == NULL) { - pc.printf("Cannot use USB Memory\r\n"); - pc.printf("FILE == NULL\r\n"); - usb_memory_run = false; - } else { - usb_memory_run = true; - char tmp[100]; - sprintf(tmp,"Hello fun USB stick World: %d!\r\n", n++); - fprintf(fp, tmp); - fclose(fp); - } - ThisThread::sleep_for(2000); - pc.printf("again\r\n"); - } -} - -int main() -{ - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); - ThisThread::sleep_for(500); - - Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 6); - pc.printf("line:%d\r\n", __LINE__); - - lcd.Clear(LCD_COLOR_BLUE); - lcd.SetBackColor(LCD_COLOR_BLUE); - lcd.SetTextColor(LCD_COLOR_WHITE); - - BSP_LCD_SetFont(&Font24); - lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); - - while(true) { - // WARNING: LEDs are OFF - led_green = 1; - led_orange = 1; - led_red = 1; - led_blue = 1; - ThisThread::sleep_for(200); - // WARNING: LEDs are ON - led_green = 0; - led_orange = 0; - led_red = 0; - led_blue = 0; - ThisThread::sleep_for(1000); - } -} - -#endif
--- a/z_example/7_USBMemory_copy0.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -// Original -// https://os.mbed.com/users/jeonbc/code/stm32-disco-example/ -// -// Modified by K.Arai -// July 25th, 2019 -// - -#include "select_program.h" -//#define EXAMPLE_7_USB_MSD -//#ifdef EXAMPLE_7_USB_MSD -#if 0 - -#include <stdlib.h> - -#include "mbed.h" -#include "LCD_DISCO_F769NI.h" -#include "USBHostMSD.h" -#include "FATFileSystem.h" - -LCD_DISCO_F769NI lcd; - -DigitalOut led_green(LED1); -DigitalOut led_orange(LED2); -DigitalOut led_red(LED3); -DigitalOut led_blue(LED4); - -Serial pc(SERIAL_TX, SERIAL_RX, 115200); - -USBHostMSD msd; -FATFileSystem fs("usb"); - -void msd_task(void const *) -{ - int i = 0; - int err; - - printf("wait for usb memory stick insertion\r\n"); - while(1) { - //pc.printf("line:%d\r\n", __LINE__); - wait_ms(500); - // try to connect a MSD device - while(!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - wait_ms(500); - } - if (fs.mount(&msd) != 0) { - pc.printf("line:%d\r\n", __LINE__); - continue; - } else { - pc.printf("file system mounted\n"); - } - - pc.printf("line:%d\r\n", __LINE__); - if (!msd.connect()) { - pc.printf("line:%d\r\n", __LINE__); - continue; - } - - // in a loop, append a file - // if the device is disconnected, we try to connect it again - - // append a file - File file; - err = file.open(&fs, "test1.txt", O_WRONLY | O_CREAT |O_APPEND); - - pc.printf("line:%d\r\n", __LINE__); - if (err == 0) { - char tmp[100]; - sprintf(tmp,"Hello fun USB stick World: %d!\r\n", i++); - file.write(tmp,strlen(tmp)); - sprintf(tmp,"Goodbye World!\r\n"); - file.write(tmp,strlen(tmp)); - file.close(); - } else { - pc.printf("FILE == NULL\r\n"); - } - ThisThread::sleep_for(500); - pc.printf("again\n"); - // if device disconnected, try to connect again - while (msd.connected()) { - wait_ms(500); - } - while (fs.unmount() < 0) { - wait_ms(500); - pc.printf("unmount\n"); - } - } -} - -int main() -{ - pc.baud(115200); - - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); - ThisThread::sleep_for(500); - - Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 6); - pc.printf("line:%d\r\n", __LINE__); - - lcd.Clear(LCD_COLOR_BLUE); - lcd.SetBackColor(LCD_COLOR_BLUE); - lcd.SetTextColor(LCD_COLOR_WHITE); - - BSP_LCD_SetFont(&Font24); - lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); - - while(true) { - // WARNING: LEDs are OFF - led_green = 1; - led_orange = 1; - led_red = 1; - led_blue = 1; - ThisThread::sleep_for(200); - // WARNING: LEDs are ON - led_green = 0; - led_orange = 0; - led_red = 0; - led_blue = 0; - ThisThread::sleep_for(1000); - } -} - -#endif
--- a/z_example/7_porting.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -#if 0 -#if USB_NOT_USE==0 -void tsk_write_usb(void const *args) -{ - FATFileSystem fsu("usb"); - FILE *fp; - - while(!msd.connect()) { - DBG("Step(%u)\r\n", __LINE__); - wait_ms(20); - } - if (msd.connected() == true){ - if (fsu.mount(&msd) == 0) { - usb_memory_run = true; - DBG("Step(%u)\r\n", __LINE__); - fp = fopen(name_usb_txt, "a"); - if (fp != 0) { - pc.printf("USBdisk:open %s\r\n", name_usb_txt); - usb_memory_run = true; - } else { - pc.printf("Cannot use USB memory\r\n"); - usb_memory_run = false; - } - fclose(fp); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - while (true) { - osEvent evt = mail_box1.get(); - if(file_write_enabale == true){ - while(msd.connected() == false) { - while(!msd.connect()) { - DBG("Step(%u)\r\n", __LINE__); - wait_ms(20); - } - pc.printf("Step(%u)\r\n", __LINE__); - } - if (msd.connected() == true){ - DBG("Step(%u)\r\n", __LINE__); - usb_memory_run = true; - if (fsu.mount(&msd) == 0) { - DBG("Step(%u)\r\n", __LINE__); - } - } else { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } - fp = fopen(name_usb_txt, "a"); - wait_ms(5); - if(fp == NULL) { - pc.printf("Cannot use USB Memory\r\n"); - usb_memory_run = false; - } else { - usb_memory_run = true; - } - if (evt.status == osEventMail) { - mail_t *mail = (mail_t*)evt.value.p; - DBG(mail->all_data); - if (usb_memory_run == true){ - fprintf(fp, mail->all_data); - } - wait_ms(5); - mail_box1.free(mail); - } else { - pc.printf("ERROR-Mail1\r\n"); - } - wait_ms(5); - fclose(fp); - } else { - if (evt.status == osEventMail) { - mail_t *mail = (mail_t*)evt.value.p; - mail_box0.free(mail); - } - } - } -} -#endif -#endif \ No newline at end of file
--- a/z_example/8_audio.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -// Original -// https://os.mbed.com/teams/ST/code/DISCO-F769NI_AUDIO_demo/ -// -// Modified by K.Arai -// July 23rd, 2019 -// - -#include "select_program.h" -//#define EXAMPLE_8_AUDIO -#ifdef EXAMPLE_8_AUDIO - -#include "mbed.h" -#include "stm32f769i_discovery.h" -#include "stm32f769i_discovery_audio.h" - -Serial pc(USBTX, USBRX, 115200); - -static void CopyBuffer(int16_t *pbuffer1, int16_t *pbuffer2, uint16_t BufferSize); - -#define SCRATCH_BUFF_SIZE 1024 -#define RECORD_BUFFER_SIZE 4096 - -typedef enum { - BUFFER_OFFSET_NONE = 0, - BUFFER_OFFSET_HALF = 1, - BUFFER_OFFSET_FULL = 2, -} BUFFER_StateTypeDef; - -volatile uint32_t audio_rec_buffer_state = BUFFER_OFFSET_NONE; -int32_t Scratch[SCRATCH_BUFF_SIZE]; - -/* Buffer containing the PCM samples coming from the microphone */ -int16_t RecordBuffer[RECORD_BUFFER_SIZE]; - -/* Buffer used to stream the recorded PCM samples towards the audio codec. */ -int16_t PlaybackBuffer[RECORD_BUFFER_SIZE]; - -int main() -{ - uint32_t audio_loop_back_init = RESET ; - - printf("\n\nAUDIO LOOPBACK EXAMPLE FOR DISCO-F769NI START:\n"); - - /* Initialize Audio Recorder with 4 channels to be used */ - if (BSP_AUDIO_IN_Init(BSP_AUDIO_FREQUENCY_44K, DEFAULT_AUDIO_IN_BIT_RESOLUTION, 2*DEFAULT_AUDIO_IN_CHANNEL_NBR) == AUDIO_ERROR) { - printf("BSP_AUDIO_IN_Init error\n"); - } - - /* Allocate scratch buffers */ - if (BSP_AUDIO_IN_AllocScratch (Scratch, SCRATCH_BUFF_SIZE) == AUDIO_ERROR) { - printf("BSP_AUDIO_IN_AllocScratch error\n"); - } - - /* Start Recording */ - if (BSP_AUDIO_IN_Record((uint16_t*)&RecordBuffer[0], RECORD_BUFFER_SIZE) == AUDIO_ERROR) { - printf("BSP_AUDIO_IN_Record error\n"); - } - uint8_t ChannelNumber = BSP_AUDIO_IN_GetChannelNumber(); - - audio_rec_buffer_state = BUFFER_OFFSET_NONE; - - while (1) { - /* 1st or 2nd half of the record buffer ready for being copied to the playbakc buffer */ - if(audio_rec_buffer_state != BUFFER_OFFSET_NONE) { - /* Copy half of the record buffer to the playback buffer */ - if(audio_rec_buffer_state == BUFFER_OFFSET_HALF) { - CopyBuffer(&PlaybackBuffer[0], &RecordBuffer[0], RECORD_BUFFER_SIZE/2); - if (audio_loop_back_init == RESET) { - /* Initialize the audio device*/ - if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 70, BSP_AUDIO_FREQUENCY_44K) == AUDIO_ERROR) { - printf("BSP_AUDIO_OUT_Init error\n"); - } - if(ChannelNumber > 2) { - BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_0123); - } else { - BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02); - } - - /* Play the recorded buffer */ - if (BSP_AUDIO_OUT_Play((uint16_t *) &PlaybackBuffer[0], 2*RECORD_BUFFER_SIZE) == AUDIO_ERROR) { - printf("BSP_AUDIO_OUT_Play error\n"); - } - /* Audio device is initialized only once */ - audio_loop_back_init = SET; - } - - - } else { /* if(audio_rec_buffer_state == BUFFER_OFFSET_FULL)*/ - CopyBuffer(&PlaybackBuffer[RECORD_BUFFER_SIZE/2], &RecordBuffer[RECORD_BUFFER_SIZE/2], RECORD_BUFFER_SIZE/2); - } - - /* Wait for next data */ - audio_rec_buffer_state = BUFFER_OFFSET_NONE; - } - } -} - -/*------------------------------------------------------------------------------------- - Callbacks implementation: - the callbacks API are defined __weak in the stm32f769i_discovery_audio.c file - and their implementation should be done in the user code if they are needed. - Below some examples of callback implementations. - -------------------------------------------------------------------------------------*/ -/** - * @brief Manages the DMA Transfer complete interrupt. - * @param None - * @retval None - */ -void BSP_AUDIO_IN_TransferComplete_CallBack(void) -{ - audio_rec_buffer_state = BUFFER_OFFSET_FULL; -} - -/** - * @brief Manages the DMA Half Transfer complete interrupt. - * @param None - * @retval None - */ -void BSP_AUDIO_IN_HalfTransfer_CallBack(void) -{ - audio_rec_buffer_state = BUFFER_OFFSET_HALF; -} - -/** - * @brief Audio IN Error callback function. - * @param None - * @retval None - */ -void BSP_AUDIO_IN_Error_CallBack(void) -{ - printf("BSP_AUDIO_IN_Error_CallBack\n"); -} - - -/** - * @brief Copy content of pbuffer2 to pbuffer1 - * @param None - * @retval None - */ -static void CopyBuffer(int16_t *pbuffer1, int16_t *pbuffer2, uint16_t BufferSize) -{ - uint32_t i = 0; - for(i = 0; i < BufferSize; i++) { - pbuffer1[i] = pbuffer2[i]; - } -} - -#endif
--- a/z_example/9_Mandelbrot.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -//--------------------------------------------------------------- -// Mandelbrot set generator -// -// Mandelbrot set is displayed using 3 kinds of color pattern. -// Tap the Mandelbrot set on the screen, expanded figure by a -// factor of two around the tapped position is displayed. -// -// 2016/02/22, Copyright (c) 2016 MIKAMI, Naoki -//--------------------------------------------------------------- -// Modified by JH1PJL/K.Arai April 26th,2018 for DISCO-F469NI -// Modified by JH1PJL/K.Arai July 25th,2019 for DISCO-F769NI - -#include "select_program.h" -//#define EXAMPLE_9_MANDEL -#ifdef EXAMPLE_9_MANDEL - -#include "button_group.hpp" -#include "mandelbrot.hpp" - -using namespace Mikami; - -struct PointF -{ - PointF() {} - PointF(float x0, float y0) : x(x0), y(y0) {} - float x, y; -}; - -TS_DISCO_F769NI ts_; -LCD_DISCO_F769NI lcd_; -Serial pc(USBTX, USBRX, 115200); - -const int X0_ = 0; // origin of x axis -const int Y0_ = 0; // origin of y axis - -const int NX_ = 670; // number of pixels for horizon -const int NY_ = 542; // number of pixels for vertical - -void Redraw(MandelbrotBase *mandel, - float wH, float hH, PointF xy, int level, - float &x1, float &x2, float &y1, float &y2) -{ - x1 = xy.x - wH; - x2 = xy.x + wH; - y1 = xy.y - hH; - y2 = xy.y + hH; - - char str[16]; - lcd_.SetTextColor(LCD_COLOR_WHITE); - lcd_.DisplayStringAt(520, 424, (uint8_t *)str, LEFT_MODE); - sprintf(str, "x:%7.3f", xy.x); - lcd_.DisplayStringAt(520, 440, (uint8_t *)str, LEFT_MODE); - sprintf(str, "y:%7.3f", -xy.y); - lcd_.DisplayStringAt(520, 456, (uint8_t *)str, LEFT_MODE); - mandel->Display(x1, x2, y1, y2); -} - -int main() -{ - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - pc.printf("Start Mandelbrot picture\r\n"); - const int LEVEL = 18; - PointF xy[LEVEL]; // corresponding to touched position - - uint32_t backColor = 0xFF006A6C; // teal green - uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button - - // region to be displayed - float x1 = -2.3f; - float x2 = 0.9f; - float y1 = -1.3f; - float y2 = 1.3f; - - float wH = (x2 - x1)/2.0f; // half width of region - float hH = (y2 - y1)/2.0f; // half height of region - - xy[0] = PointF(x1 + wH, y1 + hH); - - lcd_.Clear(backColor); - - MandelbrotBase *mandel[3]; - mandel[0] = new MandelbrotBW(lcd_, X0_, Y0_, NX_, NY_- 60); - mandel[1] = new MandelbrotColor1(lcd_, X0_, Y0_, NX_, NY_- 60); - mandel[2] = new MandelbrotColor2(lcd_, X0_, Y0_, NX_, NY_- 60); - - const string strButton[3] = {"B & W", "Color1", "Color2"}; - ButtonGroup bGroup(lcd_, ts_, 680, Y0_, 120, 80, - LCD_COLOR_BLUE, backColor, - 3, strButton, 0, 5, 1, Font24); - Button back(lcd_, ts_, 680, 390+Y0_, 120, 80, - LCD_COLOR_BLUE, backColor, "Back", Font24); - back.Draw(inActive, LCD_COLOR_GRAY); - - - // area of Mandelbrot set - Button area(lcd_, ts_, X0_, Y0_, NX_, NY_, backColor, backColor); - - lcd_.SetTextColor(LCD_COLOR_WHITE); - lcd_.SetFont(&Font24); - lcd_.DisplayStringAt(280, 460, (uint8_t *)"Mandelbrot set", LEFT_MODE); - - int pattern = -1; - int level = 0; - bool first = true; - while (true){ - int num = -1; - // select color pattern and display - if (bGroup.GetTouchedNumber(num) && (pattern != num)){ - bGroup.Draw(num, LCD_COLOR_DARKBLUE); - mandel[num]->Display(x1, x2, y1, y2); - pattern = num; - bGroup.Redraw(num); - - if (first){ - lcd_.SetBackColor(backColor); - lcd_.SetFont(&Font20); - lcd_.DisplayStringAt(680, LINE(16), (uint8_t *)"Tap to", - LEFT_MODE); - lcd_.DisplayStringAt(680, LINE(17), (uint8_t *)"Zoom in.", - LEFT_MODE); - first = false; - } - } - - // expand twice around tapped point - if (area.Touched() && (pattern != -1)){ - TS_StateTypeDef state = Button::GottenState(); - - uint16_t x = state.touchX[0] - X0_; - uint16_t y = state.touchY[0] - Y0_; - - lcd_.SetBackColor(backColor); - if (++level < LEVEL){ - xy[level] = PointF(mandel[pattern]->Fx(x), - mandel[pattern]->Fy(y)); - wH = wH/2.0f; - hH = hH/2.0f; - - Redraw(mandel[pattern], wH, hH, - xy[level], level, x1, x2, y1, y2); - } else { - lcd_.SetFont(&Font24); - lcd_.DisplayStringAt(X0_+76, 260, - (uint8_t *)" No more expand! ", - LEFT_MODE); - level = LEVEL - 1 ; - } - back.Redraw(); - } - - // "Back" button tapped - if (back.Touched() && level > 0){ - back.Draw(LCD_COLOR_DARKBLUE); - lcd_.SetBackColor(backColor); - if (level > 0){ - level--; - wH = wH*2.0f; - hH = hH*2.0f; - - Redraw(mandel[pattern], wH, hH, xy[level], - level, x1, x2, y1, y2); - if (level > 0){ - back.Redraw(); - } else { - back.Draw(inActive, LCD_COLOR_GRAY); - } - } - } - wait(0.1f); - } -} -#endif
--- a/zz_common/drawImage.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: August 4th, 2019 - */ - -/* - https://os.mbed.com/users/Lightsource/code/DISCO-F746NG_BMP_FROM_SDCARD/ - https://www.gimp.org/downloads/ - https://os.mbed.com/questions/69098/how-can-I-load-an-image-to-screen/#answer14107 - */ - -#include "select_program.h" -#if defined(NIOI_SENSOR) || defined(EXAMPLE_10_BITMAP) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "FATFileSystem.h" -#include "LCD_DISCO_F769NI.h" -#include "stm32f769i_discovery_lcd.h" - -// Definition ----------------------------------------------------------------- -#define DEBUG 1 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void drawImage(const char * name, uint16_t x, uint16_t y); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void drawImage(const char * name, uint16_t x, uint16_t y) -{ - uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; - int fileSize; - char * buffer; - char * buf; - - FILE *image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - //obtain file size: - fseek(image, 0, SEEK_END); - fileSize = ftell(image); - DBG("fileSize=%d\r\n", fileSize); - fclose(image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize); - - image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - fread(buffer, 1, fileSize, image); - fclose(image); - - //Draw image - lcd.DrawBitmap(x,y,(uint8_t *)buffer); - //Free allocated memory - free(buffer); -} - -#endif
--- a/zz_common/drawImage_copy0.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: July 30th, 2019 - */ - -/* - https://os.mbed.com/users/Lightsource/code/DISCO-F746NG_BMP_FROM_SDCARD/ - https://www.gimp.org/downloads/ - https://os.mbed.com/questions/69098/how-can-I-load-an-image-to-screen/#answer14107 - */ - -//#include "select_program.h" -#if defined(NIOI_SENSOR) || defined(EXAMPLE_10_BITMAP) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "FATFileSystem.h" -#include "LCD_DISCO_F769NI.h" -#include "stm32f769i_discovery_lcd.h" - -// Definition ----------------------------------------------------------------- - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -//extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); - - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -#if 0 -void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos) -{ - uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; - uint32_t address; - uint32_t input_color_mode = 0; - char filename[50]; - int i, fileSize; - char * buffer; - - i=0; - while (*Name_BMP!='\0') { - filename[i++]=*Name_BMP++; - } - - filename[i] = 0; - FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file - - // obtain file size: - fseek (Image, 0, SEEK_END); - fileSize = ftell (Image); - rewind (Image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize/2); - - // copy the file into the buffer: - fseek (Image, 0, SEEK_SET ); // set SD file data start position - fread (buffer,1,fileSize,Image); - fclose (Image); - - /* Get bitmap data address offset */ - index = *(__IO uint16_t *) (buffer + 10); - index |= (*(__IO uint16_t *) (buffer + 12)) << 16; - - /* Read bitmap width */ - width = *(uint16_t *) (buffer + 18); - width |= (*(uint16_t *) (buffer + 20)) << 16; - - /* Read bitmap height */ - height = *(uint16_t *) (buffer + 22); - height |= (*(uint16_t *) (buffer + 24)) << 16; - - /* Read bit/pixel */ - bit_pixel = *(uint16_t *) (buffer + 28); - - /* Set the address */ - //address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); - address = hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); - - /* Get the layer pixel format */ - if ((bit_pixel/8) == 4) { - input_color_mode = CM_ARGB8888; - } else if ((bit_pixel/8) == 2) { - input_color_mode = CM_RGB565; - } else { - input_color_mode = CM_RGB888; - } - - /* Bypass the bitmap header */ - buffer += (index + (width * (height - 1) * (bit_pixel/8))); - - /* Convert picture to ARGB8888 pixel format */ - for(index=0; index < height; index++) { - /* Pixel format conversion */ - LL_ConvertLineToARGB8888((uint32_t *)buffer, (uint32_t *)address, width, input_color_mode); - - /* Increment the source and destination buffers */ - address+= (BSP_LCD_GetXSize()*4); - buffer -= width*(bit_pixel/8); - } - free (buffer); -} -#endif -#if 0 -void drawImage(const char * name, uint16_t x, uint16_t y) -{ - int fileSize; - char * buffer; - - FILE *image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - //obtain file size: - fseek (image, 0, SEEK_END); - fileSize = ftell (image); - rewind (image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize); - // copy the file into the buffer: - fseek (image, 0, SEEK_SET ); - // set SD file data start position - fread (buffer,1,fileSize,image); - fclose (image); - - //Draw image - lcd.DrawBitmap(x,y,(uint8_t *)buffer); - //Free allocated memory - free (buffer); -} -#endif -#endif
--- a/zz_common/drawImage_copy1.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: July 30th, 2019 - */ - -/* - https://os.mbed.com/users/Lightsource/code/DISCO-F746NG_BMP_FROM_SDCARD/ - https://www.gimp.org/downloads/ - https://os.mbed.com/questions/69098/how-can-I-load-an-image-to-screen/#answer14107 - */ - -//#include "select_program.h" -#if defined(NIOI_SENSOR) || defined(EXAMPLE_10_BITMAP) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "FATFileSystem.h" -#include "LCD_DISCO_F769NI.h" -#include "stm32f769i_discovery_lcd.h" - -// Definition ----------------------------------------------------------------- - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -//extern void drawImage(const char * name, uint16_t x, uint16_t y); -//extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); - - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -#if 0 -void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos) -{ - uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; - uint32_t address; - uint32_t input_color_mode = 0; - char filename[50]; - int i, fileSize; - char * buffer; - - i=0; - while (*Name_BMP!='\0') { - filename[i++]=*Name_BMP++; - } - - filename[i] = 0; - FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file - - // obtain file size: - fseek (Image, 0, SEEK_END); - fileSize = ftell (Image); - rewind (Image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize/2); - - // copy the file into the buffer: - fseek (Image, 0, SEEK_SET ); // set SD file data start position - fread (buffer,1,fileSize,Image); - fclose (Image); - - /* Get bitmap data address offset */ - index = *(__IO uint16_t *) (buffer + 10); - index |= (*(__IO uint16_t *) (buffer + 12)) << 16; - - /* Read bitmap width */ - width = *(uint16_t *) (buffer + 18); - width |= (*(uint16_t *) (buffer + 20)) << 16; - - /* Read bitmap height */ - height = *(uint16_t *) (buffer + 22); - height |= (*(uint16_t *) (buffer + 24)) << 16; - - /* Read bit/pixel */ - bit_pixel = *(uint16_t *) (buffer + 28); - - /* Set the address */ - //address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); - address = hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); - - /* Get the layer pixel format */ - if ((bit_pixel/8) == 4) { - input_color_mode = CM_ARGB8888; - } else if ((bit_pixel/8) == 2) { - input_color_mode = CM_RGB565; - } else { - input_color_mode = CM_RGB888; - } - - /* Bypass the bitmap header */ - buffer += (index + (width * (height - 1) * (bit_pixel/8))); - - /* Convert picture to ARGB8888 pixel format */ - for(index=0; index < height; index++) { - /* Pixel format conversion */ - LL_ConvertLineToARGB8888((uint32_t *)buffer, (uint32_t *)address, width, input_color_mode); - - /* Increment the source and destination buffers */ - address+= (BSP_LCD_GetXSize()*4); - buffer -= width*(bit_pixel/8); - } - free (buffer); -} -#endif -#if 1 -void drawImage(const char * name, uint16_t x, uint16_t y) -{ - int fileSize; - char * buffer; - - FILE *image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - //obtain file size: - fseek (image, 0, SEEK_END); - fileSize = ftell (image); - rewind (image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize); - // copy the file into the buffer: - fseek (image, 0, SEEK_SET ); - // set SD file data start position - fread (buffer,1,fileSize,image); - fclose (image); - - //Draw image - lcd.DrawBitmap(x,y,(uint8_t *)buffer); - //Free allocated memory - free (buffer); -} -#endif -#endif
--- a/zz_common/drawImage_copy2.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: August 4th, 2019 - */ - -/* - https://os.mbed.com/users/Lightsource/code/DISCO-F746NG_BMP_FROM_SDCARD/ - https://www.gimp.org/downloads/ - https://os.mbed.com/questions/69098/how-can-I-load-an-image-to-screen/#answer14107 - */ - -//#include "select_program.h" -#if defined(NIOI_SENSOR) || defined(EXAMPLE_10_BITMAP) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "FATFileSystem.h" -#include "LCD_DISCO_F769NI.h" -#include "stm32f769i_discovery_lcd.h" - -// Definition ----------------------------------------------------------------- -#define DEBUG 1 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void drawImage(const char * name, uint16_t x, uint16_t y); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void drawImage(const char * name, uint16_t x, uint16_t y) -{ - uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; - int fileSize; - char * buffer; - char * buf; - - FILE *image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - //obtain file size: - fseek(image, 0, SEEK_END); - fileSize = ftell(image); - DBG("fileSize=%d\r\n", fileSize); - fclose(image); - //rewind(image); - - // allocate memory to contain the whole file: - buffer = (char*) malloc (sizeof(char)*fileSize); -#if 0 - buf = buffer; - for (int i = 0; i < fileSize; i += 4) { - *(__IO uint32_t *) buf = 0xff; - buf += 4; - } -#endif -#if 0 - // copy the file into the buffer: - fseek(image, 0, SEEK_SET); - //wait_ms(10); - // set SD file data start position - fread(buffer, 1, fileSize, image); - wait_ms(10); - // copy the file into the buffer: - fseek(image, 0, SEEK_SET); - //wait_ms(10); - // set SD file data start position - fread(buffer, 1, fileSize, image); - wait_ms(10); -#else - image = fopen(name, "rb"); // open the bmp file - if (image == 0) { - pc.printf("%s is not found in the disk\r\n", name); - return; - } - fread(buffer, 1, fileSize, image); -#endif - fclose(image); - - //Draw image - lcd.DrawBitmap(x,y,(uint8_t *)buffer); - //Free allocated memory - free(buffer); -} - -#endif
--- a/zz_common/draw_bitmap.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -// https://os.mbed.com/users/okano/code/bmp_8bit_per_pixel_format/ - -#if 0 - -#include "mbed.h" // for mbed -LocalFileSystem local("local"); // for mbed to access local file system - -/* - * - * BMP file data handler sample - * - * reference : http://www.umekkii.jp/data/computer/file_format/bitmap.cgi - * - */ - -#include <stdio.h> - -//#define SOURCE_FILE "/local/small.bmp" -#define SOURCE_FILE "/local/pre4.bmp" -//#define SOURCE_FILE "pre_dsp_4.bmp" - -#define BUFFER_SIZE 1024 - -typedef struct bmp_header_st { - unsigned short bfType __attribute__((packed)); - unsigned long bfSize __attribute__((packed)); - unsigned short bfReserved1 __attribute__((packed)); - unsigned short bfReserved2 __attribute__((packed)); - unsigned long bfOffBits __attribute__((packed)); - - unsigned long biSize __attribute__((packed)); - long biWidth __attribute__((packed)); - long biHeight __attribute__((packed)); - unsigned short biPlanes __attribute__((packed)); - unsigned short biBitCount __attribute__((packed)); - unsigned long biCompression __attribute__((packed)); - unsigned long biSizeImage __attribute__((packed)); - long biXPixPerMeter __attribute__((packed)); - long biYPixPerMeter __attribute__((packed)); - unsigned long biClrUsed __attribute__((packed)); - unsigned long biCirImportant __attribute__((packed)); -} -bmp_header; - -typedef struct color_palette_st { - unsigned char red; - unsigned char green; - unsigned char blue; - unsigned char dummy; -} -color_palette; - - -int main() { - unsigned char buffer[ BUFFER_SIZE ]; - FILE *fs; - bmp_header bh; - color_palette cp[256]; - unsigned long readsize; - unsigned long i; - unsigned long ofset = 0; - - printf( "BMP file access sample\r\n"); - - if ( NULL == (fs = fopen( SOURCE_FILE, "rb" )) ) { - printf( "file open error when oening file \"%s\"\r\n", SOURCE_FILE ); - return ( 1 ); - } - - /* - * reading header - */ - - fread( &bh, sizeof( bh ), 1, fs ); - - printf( " bfType : 0x%04X\r\n", bh.bfType ); - printf( " bfSize : %ld\r\n", bh.bfSize ); - printf( " bfOffBits : %ld\r\n", bh.bfOffBits ); - printf( " biSize : %lu\r\n", bh.biSize ); - printf( " biWidth : %ld\r\n", bh.biWidth ); - printf( " biHeight : %ld\r\n", bh.biHeight ); - printf( " biPlanes : %d\r\n", bh.biPlanes ); - printf( " biBitCount : %d\r\n", bh.biBitCount ); - printf( " biCompression : %lu\r\n", bh.biCompression ); - printf( " biSizeImage : %lu\r\n", bh.biSizeImage ); - printf( " biXPixPerMeter : %ld\r\n", bh.biXPixPerMeter ); - printf( " biYPixPerMeter : %ld\r\n", bh.biYPixPerMeter ); - printf( " biClrUsed : %lu\r\n", bh.biClrUsed ); - printf( " biCirImportant : %lu\r\n", bh.biCirImportant ); - - /* - * checking header - */ - - if ( (bh.bfType != 0x4D42) - || (bh.bfOffBits != 54 + 256 * sizeof( color_palette ) ) - || (bh.biBitCount != 8) - || (bh.biCompression != 0) - ) { - printf( "unsupported file format\r\n" ); - return ( 1 ); - } - - /* - * header information - */ - - printf( "header read, the image data size is %lu bytes\r\n", bh.bfSize ); - printf( " the image data size is %lu bytes\r\n", bh.biSizeImage ); - printf( " horizontal size %lu pixels\r\n", bh.biWidth ); - printf( " vertical size %lu pixels\r\n", bh.biHeight ); - - /* - * read color palette - */ - - for ( i = 0; i < 256; i++ ) { - fread( &(cp[i]), sizeof( color_palette ), 1, fs ); -// printf( "cp 0x%02X : 0x%02X - 0x%02X - 0x%02X\r\n", i, (cp[i]).red, (cp[i]).green, (cp[i]).blue ); - } - - - while ( 0 != (readsize = fread( buffer, sizeof( unsigned char ) , BUFFER_SIZE, fs )) ) { - for ( i = 0; i < readsize; i++ ) { -// printf( " %6lX : 0x%02X, 0x%02X, 0x%02X\r\n", ofset, cp[ buffer[i] ].red, cp[ buffer[i] ].green, cp[ buffer[i] ].blue ); - ofset++; - } - } - - printf( "done.\r\n\r\n" ); -} - -#endif \ No newline at end of file
--- a/zz_common/opening.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -/* - * Mbed function - * - * Created: July 30th, 2019 - * Revised: July 30th, 2019 - */ - -#include "select_program.h" -#if defined(NIOI_SENSOR) - -// Include -------------------------------------------------------------------- -#include "mbed.h" -#include "TS_DISCO_F769NI.h" -#include "LCD_DISCO_F769NI.h" -#include "FATFileSystem.h" -#include "SDBlockDeviceDISCOF769NI.h" -#include "button.hpp" -#include "button_group.hpp" - -// Definition ----------------------------------------------------------------- -using namespace Mikami; -#define DATETIME_20190701 1561939200 // passed seconds from 1970/1/1 to 2019/7/1 -#define FOREVER 0x7fffffff - -#define DEBUG 0 - -#if DEBUG -#define DBG(...) pc.printf(__VA_ARGS__) -#else -#define DBG(...) {;} -#endif - -// Constructor ---------------------------------------------------------------- -extern Serial pc; -extern SDBlockDeviceDISCOF769NI bd; -extern FATFileSystem fs; -extern LCD_DISCO_F769NI lcd; -extern TS_DISCO_F769NI ts; - -// RAM ------------------------------------------------------------------------ -extern bool flag_opening_done; - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void task_opening_action(void const *args); -extern void drawImage(const char * name, uint16_t x, uint16_t y); -//extern void draw_bitmap(uint8_t *Name_BMP, uint32_t Xpos, uint32_t Ypos); -//extern void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp); -extern void time_enter_mode(void); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void task_opening_action(void const *args) -{ - time_t seconds; - Timer t; - - pc.printf("\x1b[2J\x1b[H %s\r\n %s %s (UTC)\r\n", - __FILE__, __DATE__, __TIME__); - pc.printf(" MBED_VERSION=%d.%d.%d\r\n", - MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); - // allocate memory to contain the whole file: - char *buf = (char*) malloc (64); - lcd.Clear(LCD_COLOR_WHITE); - DBG("line:%d\r\n", __LINE__); - //Mounting SD-based filesystem - int error = fs.mount(&bd); - DBG("line:%d\r\n", __LINE__); - if (error != 0) { - pc.printf("retrun error/Failure. %d\r\n", error); - } - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty_big0.bmp", 16, 200); - DBG("line:%d\r\n", __LINE__); - t.reset(); - t.start(); - seconds = time(NULL); - while (seconds < DATETIME_20190701) { - lcd.SetTextColor(LCD_COLOR_BLUE); - lcd.DisplayStringAt( - 0, - 400, - (uint8_t *)"Current time is NOT correct!!", - CENTER_MODE); - lcd.DisplayStringAt( - 0, - 420, - (uint8_t *)"Plese enter the time from PC VCOM terminal.", - CENTER_MODE); - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - pc.printf("Current time is NOT correct."); - pc.printf("Please enter current date and time.\r\n"); - time_enter_mode(); - seconds = time(NULL); - } - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s", buf); - uint32_t time_show = t.read(); - if (time_show < 1999) { - ThisThread::sleep_for(4000 - time_show); - } - lcd.Clear(LCD_COLOR_WHITE); - DBG("line:%d\r\n", __LINE__); - //Drawing BMP file from SD-card - drawImage("/fs/bmp/ty.bmp", 600, 6); - drawImage("/fs/bmp/nioi_title_1_line.bmp", 20,100); - - uint32_t backColor = 0xFF006A6C; // teal green - uint32_t inActive = backColor & 0xE0FFFFFF; // color for inactive button - - const string strButton[2] = {"Start measurement", "Show time"}; - ButtonGroup bGroup(lcd, ts, 465, 280, 320, 90, - LCD_COLOR_BLUE, backColor, - 2, strButton, 0, 15, 1, Font24); - DBG("line:%d\r\n", __LINE__); - - int32_t num = -1; - // select color pattern and display - while (num == -1) { - bGroup.GetTouchedNumber(num); - } - DBG("num:%d\r\n", num); - if (num == 1) { - lcd.Clear(LCD_COLOR_WHITE); - drawImage("/fs/bmp/minion480x272_new.bmp", 150, 110); - Button btn(lcd, ts, 605, 10, 180, 80, - LCD_COLOR_BLUE, LCD_COLOR_WHITE, "Finish", Font24); - DBG("line:%d\r\n", __LINE__); - lcd.SetTextColor(LCD_COLOR_BLACK); - while(true) { - seconds = time(NULL); - strftime(buf, 50, " %B %d,'%y, %H:%M:%S ", - localtime(&seconds)); - lcd.DisplayStringAt( - 0, 420, - (uint8_t *)" ", - CENTER_MODE); - lcd.DisplayStringAt(0, 420,(uint8_t *)buf, CENTER_MODE); - if (btn.Touched()) { - DBG("line:%d\r\n", __LINE__); - break; - } - if (pc.readable()) { - char c = pc.getc(); - time_enter_mode(); - seconds = time(NULL); - } - while (seconds == time(NULL)) { - ThisThread::sleep_for(100); - } - - } - } - lcd.Clear(LCD_COLOR_BLUE); - t.stop(); - //Free allocated memory - free (buf); - ThisThread::sleep_for(10); - flag_opening_done = true; - while(true) { - ThisThread::sleep_for(FOREVER); - } -} - -#endif \ No newline at end of file
--- a/zz_common/time_set.cpp Wed Aug 07 05:39:01 2019 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/* - * Mbed function - * - * Created: July 28th, 2019 - * Revised: July 30th, 2019 - */ - -#include "select_program.h" -#if defined(NIOI_SENSOR) || defined(EXAMPLE_1_CHECK_RTC) - -// Include -------------------------------------------------------------------- -#include "mbed.h" - -// Definition ----------------------------------------------------------------- - -// Constructor ---------------------------------------------------------------- -extern Serial pc; - -// RAM ------------------------------------------------------------------------ - -// ROM / Constant data -------------------------------------------------------- - -// Function prototypes -------------------------------------------------------- -extern void time_enter_mode(void); -static void chk_and_set_time(char *ptr); -static int xatoi (char **str, unsigned long *res); -static void get_line (char *buff, int len); - -//------------------------------------------------------------------------------ -// Control Program -//------------------------------------------------------------------------------ -void time_enter_mode(void) -{ - char *ptr; - char linebuf[64]; - - pc.printf("\r\nSet time into RTC\r\n"); - pc.printf(" e.g. >19 7 15 10 11 12 -> July 15th,'19, 10:11:12\r\n"); - pc.printf(" If time is fine, just hit enter\r\n"); - pc.putc('>'); - ptr = linebuf; - get_line(ptr, sizeof(linebuf)); - pc.printf("\r"); - chk_and_set_time(ptr); -} - -// Get key input data -void get_line (char *buff, int len) -{ - char c; - int idx = 0; - - for (;;) { - c = pc.getc(); - if (c == '\r') { - buff[idx++] = c; - break; - } - if ((c == '\b') && idx) { - idx--; - pc.putc(c); - pc.putc(' '); - pc.putc(c); - } - if (((uint8_t)c >= ' ') && (idx < len - 1)) { - buff[idx++] = c; - pc.putc(c); - } - } - buff[idx] = 0; - pc.putc('\n'); -} - -void chk_and_set_time(char *ptr) -{ - unsigned long p1; - struct tm t; - time_t seconds; - - if (xatoi(&ptr, &p1)) { - t.tm_year = (uint8_t)p1 + 100; - pc.printf("Year:%d ",(int)p1); - xatoi( &ptr, &p1 ); - t.tm_mon = (uint8_t)p1 - 1; - pc.printf("Month:%d ",(int)p1); - xatoi( &ptr, &p1 ); - t.tm_mday = (uint8_t)p1; - pc.printf("Day:%d ",(int)p1); - xatoi( &ptr, &p1 ); - t.tm_hour = (uint8_t)p1; - pc.printf("Hour:%d ",(int)p1); - xatoi( &ptr, &p1 ); - t.tm_min = (uint8_t)p1; - pc.printf("Min:%d ",(int)p1); - xatoi( &ptr, &p1 ); - t.tm_sec = (uint8_t)p1; - pc.printf("Sec:%d \r\n",(int)p1); - } else { - return; - } - seconds = mktime(&t); - set_time(seconds); - pc.printf( - "Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec - ); -} - -// Change string -> integer -int xatoi (char **str, unsigned long *res) -{ - unsigned long val; - unsigned char c, radix, s = 0; - - while ((c = **str) == ' ') { - (*str)++; - } - if (c == '-') { - s = 1; - c = *(++(*str)); - } - if (c == '0') { - c = *(++(*str)); - if (c <= ' ') { - *res = 0; - return 1; - } - if (c == 'x') { - radix = 16; - c = *(++(*str)); - } else { - if (c == 'b') { - radix = 2; - c = *(++(*str)); - } else { - if ((c >= '0')&&(c <= '9')) { - radix = 8; - } else { - return 0; - } - } - } - } else { - if ((c < '1')||(c > '9')) { - return 0; - } - radix = 10; - } - val = 0; - while (c > ' ') { - if (c >= 'a') { - c -= 0x20; - } - c -= '0'; - if (c >= 17) { - c -= 7; - if (c <= 9) { - return 0; - } - } - if (c >= radix) { - return 0; - } - val = val * radix + c; - c = *(++(*str)); - } - if (s) { - val = -val; - } - *res = val; - return 1; -} - -#endif