Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@80:ff42f77928ad, 2021-02-03 (annotated)
- Committer:
- f3d
- Date:
- Wed Feb 03 11:30:30 2021 +0000
- Revision:
- 80:ff42f77928ad
- Parent:
- 79:a022f7789a49
- Child:
- 81:7087ba9d18bb
Basic driver working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f3d | 80:ff42f77928ad | 1 | /* ILI9341 interface for the NRF52832 |
hyungo | 77:9140e10d79ee | 2 | */ |
hyungo | 77:9140e10d79ee | 3 | |
Jonathan Austin |
0:2757d7abb7d9 | 4 | #include "mbed.h" |
f3d | 80:ff42f77928ad | 5 | #include "display.h" |
hyungo | 77:9140e10d79ee | 6 | /* Serial */ |
hyungo | 77:9140e10d79ee | 7 | #define BAUDRATE 9600 |
f3d | 79:a022f7789a49 | 8 | Serial g_Serial_pc(P0_18, P0_14, BAUDRATE); |
hyungo | 77:9140e10d79ee | 9 | |
hyungo | 77:9140e10d79ee | 10 | /* DigitalOut */ |
hyungo | 77:9140e10d79ee | 11 | #define LED_ON 0 |
hyungo | 77:9140e10d79ee | 12 | #define LED_OFF 1 |
f3d | 80:ff42f77928ad | 13 | |
f3d | 79:a022f7789a49 | 14 | DigitalOut g_DO_LedBlue(A5, LED_OFF); |
f3d | 80:ff42f77928ad | 15 | Display display; |
f3d | 80:ff42f77928ad | 16 | |
f3d | 80:ff42f77928ad | 17 | uint32_t prbs() |
f3d | 80:ff42f77928ad | 18 | { |
f3d | 80:ff42f77928ad | 19 | // This is an unverified 31 bit PRBS generator |
f3d | 80:ff42f77928ad | 20 | // It should be maximum length but this has not been verified |
f3d | 80:ff42f77928ad | 21 | static uint32_t shift_register=0xaa551199; |
f3d | 80:ff42f77928ad | 22 | unsigned long new_bit=0; |
f3d | 80:ff42f77928ad | 23 | static int busy=0; // need to prevent re-entrancy here |
f3d | 80:ff42f77928ad | 24 | if (!busy) |
f3d | 80:ff42f77928ad | 25 | { |
f3d | 80:ff42f77928ad | 26 | busy=1; |
f3d | 80:ff42f77928ad | 27 | new_bit= ((shift_register & (1<<27))>>27) ^ ((shift_register & (1<<30))>>30); |
f3d | 80:ff42f77928ad | 28 | new_bit= ~new_bit; |
f3d | 80:ff42f77928ad | 29 | new_bit = new_bit & 1; |
f3d | 80:ff42f77928ad | 30 | shift_register=shift_register << 1; |
f3d | 80:ff42f77928ad | 31 | shift_register=shift_register | (new_bit); |
f3d | 80:ff42f77928ad | 32 | busy=0; |
f3d | 80:ff42f77928ad | 33 | } |
f3d | 80:ff42f77928ad | 34 | return shift_register & 0x7ffffff; // return 31 LSB's |
f3d | 80:ff42f77928ad | 35 | } |
f3d | 80:ff42f77928ad | 36 | uint32_t random(uint32_t lower,uint32_t upper) |
f3d | 80:ff42f77928ad | 37 | { |
f3d | 80:ff42f77928ad | 38 | return (prbs()%(upper-lower))+lower; |
f3d | 80:ff42f77928ad | 39 | } |
hyungo | 77:9140e10d79ee | 40 | int main(void) { |
f3d | 80:ff42f77928ad | 41 | |
f3d | 80:ff42f77928ad | 42 | int Count; |
f3d | 80:ff42f77928ad | 43 | display.begin(); |
f3d | 79:a022f7789a49 | 44 | |
hyungo | 77:9140e10d79ee | 45 | while(true) { |
f3d | 80:ff42f77928ad | 46 | g_Serial_pc.printf("LED Toggle\r\n"); |
hyungo | 77:9140e10d79ee | 47 | g_DO_LedBlue = !g_DO_LedBlue; |
f3d | 80:ff42f77928ad | 48 | |
f3d | 80:ff42f77928ad | 49 | for (Count = 0; Count < 200; Count++) |
f3d | 80:ff42f77928ad | 50 | { |
f3d | 80:ff42f77928ad | 51 | display.drawRectangle(random(0,240),random(0,320),random(0,240),random(0,320),random(0,0xffff)); |
f3d | 80:ff42f77928ad | 52 | } |
f3d | 80:ff42f77928ad | 53 | display.fillRectangle(0,0,240,320,0); |
f3d | 80:ff42f77928ad | 54 | for (Count = 0; Count < 200; Count++) |
f3d | 80:ff42f77928ad | 55 | { |
f3d | 80:ff42f77928ad | 56 | |
f3d | 80:ff42f77928ad | 57 | display.fillRectangle(random(0,240),random(0,320),random(0,240),random(0,320),random(0,0xffff)); |
f3d | 80:ff42f77928ad | 58 | |
f3d | 80:ff42f77928ad | 59 | } |
f3d | 80:ff42f77928ad | 60 | display.fillRectangle(0,0,240,320,0); |
f3d | 80:ff42f77928ad | 61 | for (Count = 0; Count < 200; Count++) |
f3d | 80:ff42f77928ad | 62 | { |
f3d | 80:ff42f77928ad | 63 | display.drawCircle(random(0,240),random(0,240),random(0,320),random(0,0xffff)); |
f3d | 80:ff42f77928ad | 64 | |
f3d | 80:ff42f77928ad | 65 | } |
f3d | 80:ff42f77928ad | 66 | display.fillRectangle(0,0,240,320,0); |
f3d | 80:ff42f77928ad | 67 | for (Count = 0; Count < 50; Count++) |
f3d | 80:ff42f77928ad | 68 | { |
f3d | 80:ff42f77928ad | 69 | display.fillCircle(random(0,240),random(0,320),random(0,120),random(0,0xffff)); |
f3d | 80:ff42f77928ad | 70 | |
f3d | 80:ff42f77928ad | 71 | } |
f3d | 80:ff42f77928ad | 72 | display.fillRectangle(0,0,240,320,0); |
f3d | 80:ff42f77928ad | 73 | |
Jonathan Austin |
0:2757d7abb7d9 | 74 | } |
hyungo | 77:9140e10d79ee | 75 | |
hyungo | 77:9140e10d79ee | 76 | return 0; |
Jonathan Austin |
0:2757d7abb7d9 | 77 | } |