Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8891f0495d34
Choose a base ref
...
head repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bfb961946fba
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Jul 5, 2020

  1. Copy the full SHA
    bfb9619 View commit details
Showing with 224 additions and 10 deletions.
  1. +215 −6 firmware/MEAD/AMG240160P.cpp
  2. +9 −1 firmware/MEAD/AMG240160P.h
  3. +0 −3 firmware/MEAD/main.cpp
221 changes: 215 additions & 6 deletions firmware/MEAD/AMG240160P.cpp
Original file line number Diff line number Diff line change
@@ -28,8 +28,112 @@
***********************************************************************************************************************/

#include <stm32fxxx.h>
#include <string.h>
#include "AMG240160P.h"

//8x16 character cell
struct CharacterCell8x16
{
uint8_t pixels[16];
};

//8x16 bitmap font based on https://github.com/kmar/Sweet16Font/blob/master/Sweet16mono_bmfont_0.png
//Need to specify section!
//For some reason gcc was trying to put it in .data, not .rodata
static const CharacterCell8x16 g_bitmapFont8x16[256] __attribute__((section(".rodata"))) =
{
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //00-07
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //08-0f
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //10-17
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //18-1f
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //20-27
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, //28-2f

{ 0x00, 0x00, 0x3c, 0x42, 0x62, 0x52, 0x52, 0x4a, 0x4a, 0x46, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x30 = '0'
{ 0x00, 0x00, 0x20, 0x30, 0x28, 0x24, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 }, //0x31 = '1'
{ 0x00, 0x00, 0x3c, 0x42, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x7e, 0x00, 0x00, 0x00, 0x00 }, //0x32 = '2'
{ 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x38, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x33 = '3'
{ 0x00, 0x00, 0x20, 0x30, 0x28, 0x24, 0x22, 0x7e, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 }, //0x34 = '4'
{ 0x00, 0x00, 0x7e, 0x02, 0x02, 0x02, 0x3e, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x35 = '5'
{ 0x00, 0x00, 0x38, 0x04, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x36 = '6'
{ 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x20, 0x10, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x37 = '7'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x38 = '8'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x39 = '9'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x3a = ':'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00 }, //0x3b = ';'
{ 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00 }, //0x3c = '<'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //0x3d = '='
{ 0x00, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00 }, //0x3e = '>'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x40, 0x20, 0x10, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x3f = '?'

{ 0x00, 0x00, 0x00, 0x3c, 0x42, 0x99, 0xa1, 0xb9, 0xa5, 0x79, 0x02, 0x7c, 0x00, 0x00, 0x00, 0x00 }, //0x40 = '@'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x41 = 'A'
{ 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00 }, //0x42 = 'B'
{ 0x00, 0x00, 0x3c, 0x42, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x43 = 'C'
{ 0x00, 0x00, 0x1e, 0x22, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x22, 0x1e, 0x00, 0x00, 0x00, 0x00 }, //0x44 = 'D'
{ 0x00, 0x00, 0x7e, 0x02, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x00, 0x00, 0x00, 0x00 }, //0x45 = 'E'
{ 0x00, 0x00, 0x7e, 0x02, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 }, //0x46 = 'F'
{ 0x00, 0x00, 0x3c, 0x42, 0x02, 0x02, 0x02, 0x72, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x47 = 'G'
{ 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x48 = 'H'
{ 0x00, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00 }, //0x49 = 'I'
{ 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x4a = 'J'
{ 0x00, 0x00, 0x42, 0x42, 0x22, 0x12, 0x0e, 0x12, 0x22, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x4b = 'K'
{ 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x00, 0x00, 0x00, 0x00 }, //0x4c = 'L'
{ 0x00, 0x00, 0x41, 0x63, 0x55, 0x49, 0x49, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00 }, //0x4d = 'M'
{ 0x00, 0x00, 0x42, 0x46, 0x4a, 0x52, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x4e = 'N'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x4f = 'O'

{ 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 }, //0x50 = 'P'
{ 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x52, 0x62, 0x7c, 0x40, 0x00, 0x00, 0x00 }, //0x51 = 'Q'
{ 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x3e, 0x22, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x52 = 'R'
{ 0x00, 0x00, 0x3c, 0x42, 0x02, 0x04, 0x18, 0x20, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x53 = 'S'
{ 0x00, 0x00, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x54 = 'T'
{ 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x55 = 'U'
{ 0x00, 0x00, 0x41, 0x41, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x56 = 'V'
{ 0x00, 0x00, 0x41, 0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00 }, //0x57 = 'W'
{ 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x58 = 'X'
{ 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x59 = 'Y'
{ 0x00, 0x00, 0x7e, 0x40, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x7e, 0x00, 0x00, 0x00, 0x00 }, //0x5a = 'Z'
{ 0x00, 0x00, 0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1c, 0x00, 0x00, 0x00 }, //0x5b = '['
{ 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00 }, //0x5c = '\'
{ 0x00, 0x00, 0x1c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1c, 0x00, 0x00, 0x00 }, //0x5d = ']'
{ 0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //0x5e = '^'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00 }, //0x5f = '_'

{ 0x00, 0x00, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //0x60 = '`'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x00, 0x00, 0x00, 0x00 }, //0x61 = 'a'
{ 0x00, 0x00, 0x02, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x00, 0x00, 0x00, 0x00 }, //0x62 = 'b'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x02, 0x02, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x63 = 'c'
{ 0x00, 0x00, 0x40, 0x40, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00, 0x00, 0x00, 0x00 }, //0x64 = 'd
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x65 = 'e'
{ 0x00, 0x00, 0x38, 0x44, 0x04, 0x04, 0x1e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00 }, //0x66 = 'f'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x42, 0x3c, 0x00 }, //0x67 = 'g'
{ 0x00, 0x00, 0x02, 0x02, 0x02, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x68 = 'h'
{ 0x00, 0x00, 0x00, 0x08, 0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00 }, //0x69 = 'i'
{ 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x22, 0x1c, 0x00 }, //0x6a = 'j'
{ 0x00, 0x00, 0x02, 0x02, 0x02, 0x42, 0x42, 0x22, 0x1e, 0x22, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x6b = 'k'
{ 0x00, 0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x00 }, //0x6c = 'l'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x49, 0x49, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00, 0x00, 0x00 }, //0x6d = 'm'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00 }, //0x6e = 'n'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x6f = 'o'

{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x02, 0x00 }, //0x70 = 'p'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x00 }, //0x71 = 'q'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 }, //0x72 = 'r'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x02, 0x3c, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00 }, //0x73 = 's'
{ 0x00, 0x00, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30, 0x00, 0x00, 0x00, 0x00 }, //0x74 = 't'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00, 0x00, 0x00, 0x00 }, //0x75 = 'u'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x76 = 'v'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x22, 0x00, 0x00, 0x00, 0x00 }, //0x77 = 'w'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00, 0x00 }, //0x78 = 'x'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x20, 0x1e, 0x00 }, //0x79 = 'y'
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x20, 0x10, 0x08, 0x04, 0x02, 0x7e, 0x00, 0x00, 0x00, 0x00 }, //0x7a = 'z'
{ 0x00, 0x00, 0x30, 0x08, 0x08, 0x08, 0x08, 0x06, 0x08, 0x08, 0x08, 0x08, 0x30, 0x00, 0x00, 0x00 }, //0x7b = '{'
{ 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00 }, //0x7c = '|'
{ 0x00, 0x00, 0x06, 0x08, 0x08, 0x08, 0x08, 0x30, 0x08, 0x08, 0x08, 0x08, 0x06, 0x00, 0x00, 0x00 }, //0x7d = '}'
{ 0x00, 0x00, 0x4c, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } //0x7e = '~'
};

AMG240160P::AMG240160P(SPI* spi, GPIOPin* csn, GPIOPin* rstn, GPIOPin* ctlData, Timer* usTimer)
: m_spi(spi)
, m_csn(csn)
@@ -47,10 +151,8 @@ AMG240160P::AMG240160P(SPI* spi, GPIOPin* csn, GPIOPin* rstn, GPIOPin* ctlData,
usTimer->Sleep(10000, true);
rstn->Set(1);
usTimer->Sleep(10000, true);
}

void AMG240160P::Initialize()
{
//Initialize the display
SendCommand(0xe2); //Soft reset
SendCommand(0x2b); //Power control
SendCommand(0x25); //Temp compensation
@@ -63,7 +165,7 @@ void AMG240160P::Initialize()
SendCommand(0xeb); //Bias ratio 1/12

SendCommand(0x81); //VBIAS pot
SendCommand(35);
SendCommand(50);

SendCommand(0xf1); //COM End
SendCommand(159);
@@ -73,7 +175,91 @@ void AMG240160P::Initialize()

SendCommand(0x84); //No partial display
SendCommand(0xa6); //No inverse display
SendCommand(0xad); //Enable display
SendCommand(0xaf); //Enable display in 5-bit grayscale mode

//Clear the screen
ClearScreen();

//Clear the framebuffer
for(int y=0; y<AMG240160P_FRAMEBUFFER_ROWS; y++)
{
for(int x=0; x<AMG240160P_FRAMEBUFFER_COLS; x++)
m_framebuffer[y][x] = ' ';
}

//Dummy text fill
strncpy(m_framebuffer[0], "ch0", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[2], "ch1", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[4], "ch2", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[6], "ch3", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[8], "ch4", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[10], "ch5", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[12], "ch6", AMG240160P_FRAMEBUFFER_COLS);
strncpy(m_framebuffer[14], "ch7", AMG240160P_FRAMEBUFFER_COLS);

UpdateScreen();
}

void AMG240160P::UpdateScreen()
{
SendCommand(0x70); //Row address MSBs
SendCommand(0x60); //Row address LSBs
SendCommand(0x10); //Col address MSBs
SendCommand(0x00); //Col address LSBs

//X=0 is left, Y=0 is top as seen from MMCX ports
//Each X coordinate is a block of 3 pixels
//15:11 f800 = left
//10:6 07c0 = middle
//5 dontcare
//4:0 001f = right
for(int x=0; x<80; x++)
{
for(int y=0; y<160; y++)
{
//Default to sending blank pixels
uint8_t a = 0x00;
uint8_t b = 0x00;

//Fetch the data to send for each of our 3 pixels
//TODO: support intensity grading
//Rotate by 90 deg
if(GetPixel(159-y, x*3))
a |= 0xf8;
if(GetPixel(159-y, x*3 + 1))
{
a |= 0x07;
b |= 0xc0;
}
if(GetPixel(159-y, x*3 + 2))
b |= 0x1f;

//Actually send the 3 pixels at once
SendData(a);
SendData(b);
}
}
}

/**
@brief Gets the pixel value at a given set of coordinates
*/
bool AMG240160P::GetPixel(unsigned int x, unsigned int y)
{
//Look up the character cell and the glyph for it
char ch = m_framebuffer[y/16][x/8];
CharacterCell8x16 glyph = g_bitmapFont8x16[ch];

//Cell relative coordinates
y %= 16;
x %= 8;

//Look up the bit of interest
uint8_t row = glyph.pixels[y];
if( (row >> x) & 1)
return true;

return false;
}

void AMG240160P::SendCommand(uint8_t cmd)
@@ -91,7 +277,30 @@ void AMG240160P::SendData(uint8_t data)
m_ctlData->Set(1);

m_csn->Set(0);
m_spi->BlockingWrite(cmd);
m_spi->BlockingWrite(data);
m_spi->WaitForWrites();
m_csn->Set(1);
}

void AMG240160P::ClearScreen()
{
SendCommand(0x70); //Row address MSBs
SendCommand(0x60); //Row address LSBs
SendCommand(0x10); //Col address MSBs
SendCommand(0x00); //Col address LSBs

//X=0 is left, Y=0 is top as seen from MMCX ports
//Each X coordinate is a block of 3 pixels
//15:11 f800 = left
//10:6 07c0 = middle
//5 dontcare
//4:0 001f = right
for(int x=0; x<80; x++)
{
for(int y=0; y<160; y++)
{
SendData(0x00);
SendData(0x00);
}
}
}
10 changes: 9 additions & 1 deletion firmware/MEAD/AMG240160P.h
Original file line number Diff line number Diff line change
@@ -34,19 +34,27 @@
#include <peripheral/GPIO.h>
#include <peripheral/Timer.h>

#define AMG240160P_FRAMEBUFFER_ROWS 16
#define AMG240160P_FRAMEBUFFER_COLS 20

/**
@brief Driver for an AMG240160P-W6WFDW LCD
*/
class AMG240160P
{
public:
AMG240160P(SPI* spi, GPIOPin* csn, GPIOPin* rstn, GPIOPin* ctlData, Timer* usTimer);
void Initialize();

void SendCommand(uint8_t cmd);
void SendData(uint8_t data);
void ClearScreen();
void UpdateScreen();

//The framebuffer
char m_framebuffer[AMG240160P_FRAMEBUFFER_ROWS][AMG240160P_FRAMEBUFFER_COLS];

protected:
bool GetPixel(unsigned int x, unsigned int y);

SPI* m_spi;
GPIOPin* m_csn;
3 changes: 0 additions & 3 deletions firmware/MEAD/main.cpp
Original file line number Diff line number Diff line change
@@ -90,9 +90,6 @@ int main()
static GPIOPin lcd_rst_n(&GPIOA, 2, GPIOPin::MODE_OUTPUT);
static GPIOPin lcd_ctl_data(&GPIOA, 3, GPIOPin::MODE_OUTPUT);
AMG240160P lcd(&spi, &lcd_cs_n, &lcd_rst_n, &lcd_ctl_data, &timer);
g_uart->Printf("a");
lcd.Initialize();


/*
//Read the current temperatures