test public

Dependencies:   HttpServer_snapshot_mbed-os

Committer:
anhtran
Date:
Fri Oct 18 03:09:43 2019 +0000
Revision:
0:e9fd5575b10e
abc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anhtran 0:e9fd5575b10e 1 # **Mbed Library for GR-Boards** mbed-gr-libs
anhtran 0:e9fd5575b10e 2 **Please see [here](README_JPN.md) for Japanese version.**
anhtran 0:e9fd5575b10e 3 GR-PEACH, GR-LYCHEE and RZ/A2M board library group. The library includes the following functions.
anhtran 0:e9fd5575b10e 4 * Connect camera and LCD
anhtran 0:e9fd5575b10e 5 * Connect USB memory and SD card
anhtran 0:e9fd5575b10e 6 * Cache control
anhtran 0:e9fd5575b10e 7 * JPEG conversion
anhtran 0:e9fd5575b10e 8 * RGA library (GR-PEACH only)
anhtran 0:e9fd5575b10e 9 * Audio playback
anhtran 0:e9fd5575b10e 10 * USB Host
anhtran 0:e9fd5575b10e 11 * ESP32 AT command library
anhtran 0:e9fd5575b10e 12 * DisplayApp (Image display on PC display with USB connection)
anhtran 0:e9fd5575b10e 13 * ASCII font
anhtran 0:e9fd5575b10e 14 * Communication speed of SD card
anhtran 0:e9fd5575b10e 15 * DRP (RZ/A2M only)
anhtran 0:e9fd5575b10e 16
anhtran 0:e9fd5575b10e 17
anhtran 0:e9fd5575b10e 18 ## Connect camera and LCD
anhtran 0:e9fd5575b10e 19 By using ``EasyAttach_CameraAndLCD``, it is easy to connect the camera and the LCD.
anhtran 0:e9fd5575b10e 20 Sample code : [GR-Boads_Camera_LCD_sample](https://github.com/d-kato/GR-Boads_Camera_LCD_sample)
anhtran 0:e9fd5575b10e 21 Details : [EasyAttach_CameraAndLCD/README.md](EasyAttach_CameraAndLCD/README.md)
anhtran 0:e9fd5575b10e 22
anhtran 0:e9fd5575b10e 23
anhtran 0:e9fd5575b10e 24 ## Connect USB memory and SD card
anhtran 0:e9fd5575b10e 25 By using ``SdUsbConnect class`` you can easily connect USB memory and SD card.
anhtran 0:e9fd5575b10e 26 If both devices are inserted, connect to the device you detected earlier.
anhtran 0:e9fd5575b10e 27 ```cpp
anhtran 0:e9fd5575b10e 28 #include "SdUsbConnect.h"
anhtran 0:e9fd5575b10e 29
anhtran 0:e9fd5575b10e 30 int main() {
anhtran 0:e9fd5575b10e 31 SdUsbConnect storage("storage");
anhtran 0:e9fd5575b10e 32
anhtran 0:e9fd5575b10e 33 // wait connect
anhtran 0:e9fd5575b10e 34 storage.wait_connect();
anhtran 0:e9fd5575b10e 35
anhtran 0:e9fd5575b10e 36 while (1) {
anhtran 0:e9fd5575b10e 37 // check connect
anhtran 0:e9fd5575b10e 38 if (!storage.connected()) { // disconnect
anhtran 0:e9fd5575b10e 39 printf("disconnect\r\n");
anhtran 0:e9fd5575b10e 40 break;
anhtran 0:e9fd5575b10e 41 }
anhtran 0:e9fd5575b10e 42
anhtran 0:e9fd5575b10e 43 FILE * fp = fopen("/storage/test.txt", "rb");
anhtran 0:e9fd5575b10e 44 char buf[32];
anhtran 0:e9fd5575b10e 45 fread(buf, sizeof(char), 32, fp);
anhtran 0:e9fd5575b10e 46 printf("%s", buf);
anhtran 0:e9fd5575b10e 47 fclose(fp);
anhtran 0:e9fd5575b10e 48 }
anhtran 0:e9fd5575b10e 49 }
anhtran 0:e9fd5575b10e 50 ```
anhtran 0:e9fd5575b10e 51 Sample code : [GR-Boards_Audio_WAV](https://github.com/d-kato/GR-Boards_Audio_WAV)
anhtran 0:e9fd5575b10e 52
anhtran 0:e9fd5575b10e 53
anhtran 0:e9fd5575b10e 54 ## Cache control
anhtran 0:e9fd5575b10e 55 When using DMA, you need to be conscious of cache control. DMA is an abbreviation of Direct Memory Access, and it accesses memory without CPU intervention.
anhtran 0:e9fd5575b10e 56 When writing data using the CPU, such as `buf [0] = 0x01` or `memcpy (buf, data, 64)`, it write to the cache rather than the real memory.
anhtran 0:e9fd5575b10e 57 If you try to transfer `buf` data with DMA in this state, the intended data can not be transferred because the actual memory has not been written yet.
anhtran 0:e9fd5575b10e 58 Conversely, when accessing data transferred by DMA using the CPU, if dust remains on the cache, it reads dust on the cache instead of the actual memory.
anhtran 0:e9fd5575b10e 59 When mbed code is used, both GR-PEACH and GR-LYCHEE prepare a 1 MB non-cacheable area (`NC_BSS` section).
anhtran 0:e9fd5575b10e 60 When using DMA, using this non-cache memory makes control easier.
anhtran 0:e9fd5575b10e 61 ```cpp
anhtran 0:e9fd5575b10e 62 // non-cacheable
anhtran 0:e9fd5575b10e 63 #if defined(__ICCARM__)
anhtran 0:e9fd5575b10e 64 static uint8_t buf[64]@ ".mirrorram";
anhtran 0:e9fd5575b10e 65 #else
anhtran 0:e9fd5575b10e 66 static uint8_t buf[64]__attribute((section("NC_BSS")));
anhtran 0:e9fd5575b10e 67 #endif
anhtran 0:e9fd5575b10e 68
anhtran 0:e9fd5575b10e 69 void dma_send_func() {
anhtran 0:e9fd5575b10e 70 buf[0] = 0x01;
anhtran 0:e9fd5575b10e 71 DMA_send(buf); // DMA send
anhtran 0:e9fd5575b10e 72 }
anhtran 0:e9fd5575b10e 73
anhtran 0:e9fd5575b10e 74 void dma_recv_func() {
anhtran 0:e9fd5575b10e 75 DMA_recv(buf); // DMA receive
anhtran 0:e9fd5575b10e 76 printf("%d\r\n", buf[0]);
anhtran 0:e9fd5575b10e 77 }
anhtran 0:e9fd5575b10e 78 ```
anhtran 0:e9fd5575b10e 79
anhtran 0:e9fd5575b10e 80 If non-cache memory is not used, the following cache control is required.
anhtran 0:e9fd5575b10e 81 It is necessary to align 32 bytes of memory for cache control and make the size a multiple of 32 bytes.
anhtran 0:e9fd5575b10e 82
anhtran 0:e9fd5575b10e 83 ```cpp
anhtran 0:e9fd5575b10e 84 #include "dcache-control.h" // Add header for cache control
anhtran 0:e9fd5575b10e 85
anhtran 0:e9fd5575b10e 86 // Always align memory to cache control to 32 bytes, make it multiple of 32 bytes
anhtran 0:e9fd5575b10e 87 #if defined(__ICCARM__)
anhtran 0:e9fd5575b10e 88 #pragma data_alignment=32
anhtran 0:e9fd5575b10e 89 static uint8_t buf[64];
anhtran 0:e9fd5575b10e 90 #else
anhtran 0:e9fd5575b10e 91 static uint8_t buf[64]__attribute((aligned(32)));
anhtran 0:e9fd5575b10e 92 #endif
anhtran 0:e9fd5575b10e 93
anhtran 0:e9fd5575b10e 94 void dma_send_func() {
anhtran 0:e9fd5575b10e 95 buf[0] = 0x01;
anhtran 0:e9fd5575b10e 96 dcache_clean(buf, sizeof(buf)); // Write data on cache to real memory
anhtran 0:e9fd5575b10e 97 DMA_send(buf); //DMA send
anhtran 0:e9fd5575b10e 98 }
anhtran 0:e9fd5575b10e 99
anhtran 0:e9fd5575b10e 100 void dma_recv_func() {
anhtran 0:e9fd5575b10e 101 dcache_invalid(buf, sizeof(buf)); // Discard the data on the cache in advance
anhtran 0:e9fd5575b10e 102 DMA_recv(buf); //DMA receive
anhtran 0:e9fd5575b10e 103 printf("%d\r\n", buf[0]);
anhtran 0:e9fd5575b10e 104 }
anhtran 0:e9fd5575b10e 105 ```
anhtran 0:e9fd5575b10e 106
anhtran 0:e9fd5575b10e 107
anhtran 0:e9fd5575b10e 108 ## JPEG conversion
anhtran 0:e9fd5575b10e 109 DMA is used for JPEG conversion. See above ``Cache control``.
anhtran 0:e9fd5575b10e 110 Sample code : [GR-Boads_Camera_sample](https://github.com/d-kato/GR-Boads_Camera_sample)
anhtran 0:e9fd5575b10e 111 Details : [GraphicsFramework](https://developer.mbed.org/teams/Renesas/code/GraphicsFramework/)
anhtran 0:e9fd5575b10e 112
anhtran 0:e9fd5575b10e 113
anhtran 0:e9fd5575b10e 114 ## RGA library (GR-PEACH only)
anhtran 0:e9fd5575b10e 115 Details : [GraphicsFramework](https://developer.mbed.org/teams/Renesas/code/GraphicsFramework/)
anhtran 0:e9fd5575b10e 116
anhtran 0:e9fd5575b10e 117
anhtran 0:e9fd5575b10e 118 ## Audio playback
anhtran 0:e9fd5575b10e 119 Using the ``EasyPlayback class`` you can easily playback audio.
anhtran 0:e9fd5575b10e 120 Sample code : [GR-Boards_Audio_WAV](https://github.com/d-kato/GR-Boards_Audio_WAV)
anhtran 0:e9fd5575b10e 121
anhtran 0:e9fd5575b10e 122
anhtran 0:e9fd5575b10e 123 ## USB Host
anhtran 0:e9fd5575b10e 124 Official USB host function is not yet implemented in mbed OS. I changed USBHost used by mbed classic so that it can be used with mbed OS 5.
anhtran 0:e9fd5575b10e 125 Details : [USBHost](https://developer.mbed.org/handbook/USBHost)
anhtran 0:e9fd5575b10e 126 Supplement: The USBHostMSD class has been changed considerably according to the specification of mbed OS 5.4. Please refer to ``SdUsbConnect class`` for USB memory connection.
anhtran 0:e9fd5575b10e 127
anhtran 0:e9fd5575b10e 128
anhtran 0:e9fd5575b10e 129 ## ESP32 AT command library
anhtran 0:e9fd5575b10e 130 By using ``ESP32Interface class`` you can do WiFi communication.
anhtran 0:e9fd5575b10e 131 Details : [TCPSocketWiFi_Example_for_ESP32](https://github.com/d-kato/TCPSocketWiFi_Example_for_ESP32)
anhtran 0:e9fd5575b10e 132
anhtran 0:e9fd5575b10e 133
anhtran 0:e9fd5575b10e 134 ## DisplayApp (Image display on PC display with USB connection)
anhtran 0:e9fd5575b10e 135 This is a library for displaying JPEG images in the GR-Board on the PC. Connect the USB cable to ``MicroUSB Connector (RZ/A1 Ch.0)``.
anhtran 0:e9fd5575b10e 136
anhtran 0:e9fd5575b10e 137 ![](docs/img/usb0_and_button.jpg)
anhtran 0:e9fd5575b10e 138
anhtran 0:e9fd5575b10e 139 For RZ / A2M, connect to ``USB CH.0``.
anhtran 0:e9fd5575b10e 140 If your PC isn't Windows10, you need to install the specified driver from the below URL.
anhtran 0:e9fd5575b10e 141
anhtran 0:e9fd5575b10e 142 https://os.mbed.com/handbook/USBSerial
anhtran 0:e9fd5575b10e 143
anhtran 0:e9fd5575b10e 144 Unfortunately, since that is "Unsigned driver", you cannot install as is depending on your Windows version. Since the setting method is different for each PC, please search with "Unsigned driver" keyword on the search site.
anhtran 0:e9fd5575b10e 145
anhtran 0:e9fd5575b10e 146 Applications for PC can be downloaded from the following.
anhtran 0:e9fd5575b10e 147 * [For Windows](http://gadget.renesas.com/software/displayapp.zip)
anhtran 0:e9fd5575b10e 148 * [For Mac](http://gadget.renesas.com/software/DisplayApp.app.zip)
anhtran 0:e9fd5575b10e 149
anhtran 0:e9fd5575b10e 150 Example
anhtran 0:e9fd5575b10e 151 ```cpp
anhtran 0:e9fd5575b10e 152 #include "DisplayApp.h"
anhtran 0:e9fd5575b10e 153 #include "mbed.h"
anhtran 0:e9fd5575b10e 154
anhtran 0:e9fd5575b10e 155 static uint8_t jpeg_image[] = {/* JPEG image data */};
anhtran 0:e9fd5575b10e 156
anhtran 0:e9fd5575b10e 157 int main() {
anhtran 0:e9fd5575b10e 158 DisplayApp display_app;
anhtran 0:e9fd5575b10e 159
anhtran 0:e9fd5575b10e 160 while (1) {
anhtran 0:e9fd5575b10e 161 display_app.SendJpeg(&jpeg_image[0], sizeof(jpeg_image));
anhtran 0:e9fd5575b10e 162 wait(1);
anhtran 0:e9fd5575b10e 163 }
anhtran 0:e9fd5575b10e 164 }
anhtran 0:e9fd5575b10e 165 ```
anhtran 0:e9fd5575b10e 166
anhtran 0:e9fd5575b10e 167
anhtran 0:e9fd5575b10e 168 ## ASCII font
anhtran 0:e9fd5575b10e 169 By using ``AsciiFont class`` you can draw ASCII code characters.
anhtran 0:e9fd5575b10e 170
anhtran 0:e9fd5575b10e 171 ```cpp
anhtran 0:e9fd5575b10e 172 #include "mbed.h"
anhtran 0:e9fd5575b10e 173 #include "AsciiFont.h"
anhtran 0:e9fd5575b10e 174
anhtran 0:e9fd5575b10e 175 #define WIDTH (12)
anhtran 0:e9fd5575b10e 176 #define HEIGHT (16)
anhtran 0:e9fd5575b10e 177 #define BYTE_PER_PIXEL (1u)
anhtran 0:e9fd5575b10e 178 #define STRIDE (((WIDTH * BYTE_PER_PIXEL) + 7u) & ~7u) //multiple of 8
anhtran 0:e9fd5575b10e 179
anhtran 0:e9fd5575b10e 180 uint8_t text_field[STRIDE * HEIGHT];
anhtran 0:e9fd5575b10e 181
anhtran 0:e9fd5575b10e 182 int main() {
anhtran 0:e9fd5575b10e 183 AsciiFont ascii_font(text_field, WIDTH, HEIGHT, STRIDE, BYTE_PER_PIXEL);
anhtran 0:e9fd5575b10e 184
anhtran 0:e9fd5575b10e 185 ascii_font.Erase(0xcc); // Erase text field
anhtran 0:e9fd5575b10e 186 ascii_font.DrawStr("AB", 0, 0, 0x11, 1);
anhtran 0:e9fd5575b10e 187 ascii_font.DrawChar('C', AsciiFont::CHAR_PIX_WIDTH, AsciiFont::CHAR_PIX_HEIGHT, 0x22, 1);
anhtran 0:e9fd5575b10e 188 }
anhtran 0:e9fd5575b10e 189 ```
anhtran 0:e9fd5575b10e 190
anhtran 0:e9fd5575b10e 191 ## Communication speed of SD card
anhtran 0:e9fd5575b10e 192 RZ/A2M communicates with SD speed class. If you need HS speed class or UHS speed class with RZ/A2M, please contact us from [here](https://www.renesas.com/jp/en/support/contact.html).
anhtran 0:e9fd5575b10e 193 GR-PEACH and GR-LYCHEE access an SD Card using SPI bus.
anhtran 0:e9fd5575b10e 194 Please refer to ``SdUsbConnect class`` for connection.
anhtran 0:e9fd5575b10e 195
anhtran 0:e9fd5575b10e 196
anhtran 0:e9fd5575b10e 197 ## DRP (RZ/A2M only)
anhtran 0:e9fd5575b10e 198 DRP(Dynamically Reconfigurable Processor) is the programmable hardware which have both the flexibility of software and the speed of hardware. The firmware which define processing, can be renewed immediately.
anhtran 0:e9fd5575b10e 199 Please see ``drp-for-mbed/TARGET_RZ_A2XX/r_drp/doc`` for details.