[stm32f429-discovery] General sweep to fix style according to make stylecheck.

This commit is contained in:
Piotr Esden-Tempski
2015-02-04 20:39:32 -08:00
parent c06aba1603
commit 8c6eb9ca57
26 changed files with 1091 additions and 963 deletions

View File

@@ -33,18 +33,21 @@
static volatile uint32_t system_millis;
/* Called when systick fires */
void sys_tick_handler(void) {
void sys_tick_handler(void)
{
system_millis++;
}
/* simple sleep for delay milliseconds */
void msleep(uint32_t delay) {
void msleep(uint32_t delay)
{
uint32_t wake = system_millis + delay;
while (wake > system_millis) ;
while (wake > system_millis);
}
/* Getter function for the current time */
uint32_t mtime(void) {
uint32_t mtime(void)
{
return system_millis;
}

View File

@@ -41,10 +41,10 @@
* read by the program. See the README file for a discussion of
* the failure semantics.
*/
#define RECV_BUF_SIZE 128 // Arbitrary buffer size
#define RECV_BUF_SIZE 128 /* Arbitrary buffer size */
char recv_buf[RECV_BUF_SIZE];
volatile int recv_ndx_nxt; // Next place to store
volatile int recv_ndx_cur; // Next place to read
volatile int recv_ndx_nxt; /* Next place to store */
volatile int recv_ndx_cur; /* Next place to read */
/* For interrupt handling we add a new function which is called
* when recieve interrupts happen. The name (usart1_isr) is created
@@ -57,7 +57,8 @@ volatile int recv_ndx_cur; // Next place to read
* right or it won't work. And you'll wonder where your interrupts
* are going.
*/
void usart1_isr(void) {
void usart1_isr(void)
{
uint32_t reg;
int i;
@@ -79,7 +80,8 @@ void usart1_isr(void) {
recv_ndx_nxt = i;
}
}
} while ((reg & USART_SR_RXNE) != 0); // can read back-to-back interrupts
} while ((reg & USART_SR_RXNE) != 0); /* can read back-to-back
interrupts */
}
/*
@@ -88,7 +90,8 @@ void usart1_isr(void) {
* Send the character 'c' to the USART, wait for the USART
* transmit buffer to be empty first.
*/
void console_putc(char c) {
void console_putc(char c)
{
uint32_t reg;
do {
reg = USART_SR(CONSOLE_UART);
@@ -106,10 +109,11 @@ void console_putc(char c) {
* The implementation is a bit different however, now it looks
* in the ring buffer to see if a character has arrived.
*/
char console_getc(int wait) {
char console_getc(int wait)
{
char c = 0;
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt)) ;
while ((wait != 0) && (recv_ndx_cur == recv_ndx_nxt));
if (recv_ndx_cur != recv_ndx_nxt) {
c = recv_buf[recv_ndx_cur];
recv_ndx_cur = (recv_ndx_cur + 1) % RECV_BUF_SIZE;
@@ -124,7 +128,8 @@ char console_getc(int wait) {
* after the last character, as indicated by a NUL character, is
* reached.
*/
void console_puts(char *s) {
void console_puts(char *s)
{
while (*s != '\000') {
console_putc(*s);
/* Add in a carraige return, after sending line feed */
@@ -142,7 +147,8 @@ void console_puts(char *s) {
* support for editing characters (back space and delete)
* end when a <CR> character is received.
*/
int console_gets(char *s, int len) {
int console_gets(char *s, int len)
{
char *t = s;
char c;
@@ -165,7 +171,7 @@ int console_gets(char *s, int len) {
/* update end of string with NUL */
*t = '\000';
}
return (t - s);
return t - s;
}
/*
@@ -174,7 +180,8 @@ int console_gets(char *s, int len) {
* Set the pins and clocks to create a console that we can
* use for serial messages and getting text from the user.
*/
void console_setup(int baud) {
void console_setup(int baud)
{
/* MUST enable the GPIO clock in ADDITION to the USART clock */
rcc_periph_clock_enable(RCC_GPIOA);

View File

@@ -27,7 +27,7 @@
* These define sort of the minimum "library" of functions which
* we can use on a serial port. If you wish to use a different
* USART there are several things to change:
* - CONSOLE_UART change this
* - CONSOLE_UART change this
* - Change the peripheral enable clock
* - add usartx_isr for interrupts
* - nvic_enable_interrupt(your choice of USART/UART)

View File

@@ -34,141 +34,141 @@
#define FONT_CHAR_HEIGHT 12
static const unsigned char mcm_font[] = {
0x00, 0x00, 0x00, 0x00, 0x31, 0x4A, 0x44, 0x4A, 0x31, // 0
0xBC, 0x22, 0x3B, 0x22, 0x22, 0x3b, 0x20, 0x20, 0x40, // 1
0x80, 0x61, 0x12, 0x14, 0x18, 0x10, 0x30, 0x30, 0x30, // 2
0x30, 0x48, 0x40, 0x40, 0x20, 0x30, 0x48, 0x48, 0x30, // 3
0x00, 0x00, 0x18, 0x20, 0x40, 0x78, 0x40, 0x20, 0x30, // 4
0x16, 0x0e, 0x10, 0x20, 0x40, 0x40, 0x38, 0x04, 0x18, // 5
0x80, 0x2c, 0x52, 0x12, 0x12, 0x12, 0x02, 0x02, 0x02, // 6
0x18, 0x24, 0x42, 0x42, 0x3e, 0x42, 0x42, 0x24, 0x18, // 7
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x48, 0x30, // 8
0x00, 0x00, 0x40, 0x48, 0x50, 0x60, 0x50, 0x4A, 0x44, // 9
0x40, 0x20, 0x10, 0x10, 0x10, 0x10, 0x18, 0x24, 0x42, // 10
0x80, 0x48, 0x48, 0x48, 0x48, 0x74, 0x40, 0x40, 0x40, // 11
0x00, 0x00, 0x00, 0x62, 0x22, 0x24, 0x28, 0x30, 0x20, // 12
0x08, 0x1c, 0x20, 0x18, 0x20, 0x40, 0x3c, 0x02, 0x0c, // 13
0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x24, 0x18, // 14
0x00, 0x00, 0x00, 0x3f, 0x54, 0x24, 0x24, 0x24, 0x24, // 15
0x00, 0x00, 0x00, 0x00, 0x31, 0x4A, 0x44, 0x4A, 0x31, /* 0 */
0xBC, 0x22, 0x3B, 0x22, 0x22, 0x3b, 0x20, 0x20, 0x40, /* 1 */
0x80, 0x61, 0x12, 0x14, 0x18, 0x10, 0x30, 0x30, 0x30, /* 2 */
0x30, 0x48, 0x40, 0x40, 0x20, 0x30, 0x48, 0x48, 0x30, /* 3 */
0x00, 0x00, 0x18, 0x20, 0x40, 0x78, 0x40, 0x20, 0x30, /* 4 */
0x16, 0x0e, 0x10, 0x20, 0x40, 0x40, 0x38, 0x04, 0x18, /* 5 */
0x80, 0x2c, 0x52, 0x12, 0x12, 0x12, 0x02, 0x02, 0x02, /* 6 */
0x18, 0x24, 0x42, 0x42, 0x3e, 0x42, 0x42, 0x24, 0x18, /* 7 */
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x48, 0x30, /* 8 */
0x00, 0x00, 0x40, 0x48, 0x50, 0x60, 0x50, 0x4A, 0x44, /* 9 */
0x40, 0x20, 0x10, 0x10, 0x10, 0x10, 0x18, 0x24, 0x42, /* 10 */
0x80, 0x48, 0x48, 0x48, 0x48, 0x74, 0x40, 0x40, 0x40, /* 11 */
0x00, 0x00, 0x00, 0x62, 0x22, 0x24, 0x28, 0x30, 0x20, /* 12 */
0x08, 0x1c, 0x20, 0x18, 0x20, 0x40, 0x3c, 0x02, 0x0c, /* 13 */
0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x24, 0x18, /* 14 */
0x00, 0x00, 0x00, 0x3f, 0x54, 0x24, 0x24, 0x24, 0x24, /* 15 */
0x98, 0x24, 0x42, 0x42, 0x64, 0x58, 0x40, 0x40, 0x40, // 16
0x00, 0x00, 0x00, 0x1f, 0x24, 0x42, 0x42, 0x24, 0x18, // 17
0x00, 0x00, 0x00, 0x3f, 0x48, 0x08, 0x08, 0x08, 0x08, // 18
0x00, 0x00, 0x00, 0x62, 0x24, 0x24, 0x24, 0x24, 0x18, // 19
0x10, 0x10, 0x38, 0x54, 0x54, 0x54, 0x38, 0x10, 0x10, // 20
0x00, 0x00, 0x00, 0x00, 0x62, 0x14, 0x08, 0x14, 0x23, // 21
0x80, 0x49, 0x2a, 0x2a, 0x2a, 0x1c, 0x08, 0x08, 0x08, // 22
0x00, 0x00, 0x00, 0x22, 0x41, 0x49, 0x49, 0x49, 0x36, // 23
0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x22, 0x22, 0x63, // 24
0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x50, 0x30, 0x10, // 25
0x00, 0x00, 0x04, 0x02, 0x7f, 0x02, 0x04, 0x00, 0x00, // 26
0x00, 0x00, 0x10, 0x20, 0x7f, 0x20, 0x10, 0x00, 0x00, // 27
0x08, 0x1c, 0x2a, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, // 28
0x00, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x08, 0x00, 0x00, // 29
0x7f, 0x20, 0x10, 0x08, 0x06, 0x08, 0x10, 0x20, 0x7f, // 30
0x00, 0x30, 0x45, 0x06, 0x30, 0x45, 0x06, 0x00, 0x00, // 31
0x98, 0x24, 0x42, 0x42, 0x64, 0x58, 0x40, 0x40, 0x40, /* 16 */
0x00, 0x00, 0x00, 0x1f, 0x24, 0x42, 0x42, 0x24, 0x18, /* 17 */
0x00, 0x00, 0x00, 0x3f, 0x48, 0x08, 0x08, 0x08, 0x08, /* 18 */
0x00, 0x00, 0x00, 0x62, 0x24, 0x24, 0x24, 0x24, 0x18, /* 19 */
0x10, 0x10, 0x38, 0x54, 0x54, 0x54, 0x38, 0x10, 0x10, /* 20 */
0x00, 0x00, 0x00, 0x00, 0x62, 0x14, 0x08, 0x14, 0x23, /* 21 */
0x80, 0x49, 0x2a, 0x2a, 0x2a, 0x1c, 0x08, 0x08, 0x08, /* 22 */
0x00, 0x00, 0x00, 0x22, 0x41, 0x49, 0x49, 0x49, 0x36, /* 23 */
0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x22, 0x22, 0x63, /* 24 */
0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x50, 0x30, 0x10, /* 25 */
0x00, 0x00, 0x04, 0x02, 0x7f, 0x02, 0x04, 0x00, 0x00, /* 26 */
0x00, 0x00, 0x10, 0x20, 0x7f, 0x20, 0x10, 0x00, 0x00, /* 27 */
0x08, 0x1c, 0x2a, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, /* 28 */
0x00, 0x00, 0x08, 0x00, 0x7f, 0x00, 0x08, 0x00, 0x00, /* 29 */
0x7f, 0x20, 0x10, 0x08, 0x06, 0x08, 0x10, 0x20, 0x7f, /* 30 */
0x00, 0x30, 0x45, 0x06, 0x30, 0x45, 0x06, 0x00, 0x00, /* 31 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x08, // 33
0x12, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 34
0x14, 0x14, 0x14, 0x7f, 0x14, 0x7f, 0x14, 0x14, 0x14, // 35
0x08, 0x3f, 0x48, 0x48, 0x3e, 0x09, 0x09, 0x7e, 0x08, // 36
0x20, 0x51, 0x22, 0x04, 0x08, 0x10, 0x22, 0x45, 0x02, // 37
0x38, 0x44, 0x44, 0x28, 0x10, 0x29, 0x46, 0x46, 0x39, // 38
0x20, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 39
0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, // 40
0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x08, // 41
0x80, 0x49, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x49, 0x80, // 42
0x00, 0x80, 0x80, 0x80, 0x7e, 0x80, 0x80, 0x80, 0x00, // 43
0x80, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x10, 0x20, // 44
0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, // 45
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, // 46
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, // 47
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32 */
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x08, /* 33 */
0x12, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 34 */
0x14, 0x14, 0x14, 0x7f, 0x14, 0x7f, 0x14, 0x14, 0x14, /* 35 */
0x08, 0x3f, 0x48, 0x48, 0x3e, 0x09, 0x09, 0x7e, 0x08, /* 36 */
0x20, 0x51, 0x22, 0x04, 0x08, 0x10, 0x22, 0x45, 0x02, /* 37 */
0x38, 0x44, 0x44, 0x28, 0x10, 0x29, 0x46, 0x46, 0x39, /* 38 */
0x20, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 39 */
0x08, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x08, /* 40 */
0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x08, /* 41 */
0x80, 0x49, 0x2a, 0x1c, 0x7f, 0x1c, 0x2a, 0x49, 0x80, /* 42 */
0x00, 0x80, 0x80, 0x80, 0x7e, 0x80, 0x80, 0x80, 0x00, /* 43 */
0x80, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x10, 0x20, /* 44 */
0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, /* 45 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 46 */
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, /* 47 */
0x3e, 0x41, 0x43, 0x45, 0x49, 0x51, 0x61, 0x41, 0x3e, // 48
0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, // 49
0x3e, 0x41, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x40, 0x7f, // 50
0x3e, 0x41, 0x01, 0x01, 0x1e, 0x01, 0x01, 0x41, 0x3e, // 51
0x02, 0x06, 0x0a, 0x12, 0x22, 0x7f, 0x02, 0x02, 0x02, // 52
0x7f, 0x40, 0x40, 0x40, 0x7e, 0x01, 0x01, 0x41, 0x3e, // 53
0x3e, 0x41, 0x40, 0x40, 0x7e, 0x41, 0x41, 0x41, 0x3e, // 54
0x7f, 0x41, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x10, // 55
0x3e, 0x41, 0x41, 0x41, 0x3e, 0x41, 0x41, 0x41, 0x3e, // 56
0x3f, 0x41, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x41, 0x3e, // 57
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // 58
0xa0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x10, 0x20, // 59
0x04, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x04, // 60
0x00, 0x00, 0x00, 0x7f, 0x00, 0x7f, 0x00, 0x00, 0x00, // 61
0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, // 62
0x3e, 0x41, 0x41, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, // 63
0x3e, 0x41, 0x43, 0x45, 0x49, 0x51, 0x61, 0x41, 0x3e, /* 48 */
0x08, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, /* 49 */
0x3e, 0x41, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x40, 0x7f, /* 50 */
0x3e, 0x41, 0x01, 0x01, 0x1e, 0x01, 0x01, 0x41, 0x3e, /* 51 */
0x02, 0x06, 0x0a, 0x12, 0x22, 0x7f, 0x02, 0x02, 0x02, /* 52 */
0x7f, 0x40, 0x40, 0x40, 0x7e, 0x01, 0x01, 0x41, 0x3e, /* 53 */
0x3e, 0x41, 0x40, 0x40, 0x7e, 0x41, 0x41, 0x41, 0x3e, /* 54 */
0x7f, 0x41, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x10, /* 55 */
0x3e, 0x41, 0x41, 0x41, 0x3e, 0x41, 0x41, 0x41, 0x3e, /* 56 */
0x3f, 0x41, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x41, 0x3e, /* 57 */
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, /* 58 */
0xa0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x10, 0x20, /* 59 */
0x04, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x04, /* 60 */
0x00, 0x00, 0x00, 0x7f, 0x00, 0x7f, 0x00, 0x00, 0x00, /* 61 */
0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, /* 62 */
0x3e, 0x41, 0x41, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, /* 63 */
0x3e, 0x41, 0x41, 0x1d, 0x55, 0x5e, 0x40, 0x40, 0x3e, // 64
0x1c, 0x22, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, 0x41, // 65
0x7e, 0x21, 0x21, 0x21, 0x3e, 0x21, 0x21, 0x21, 0x7e, // 66
0x1e, 0x21, 0x40, 0x40, 0x40, 0x40, 0x40, 0x21, 0x1e, // 67
0x7e, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x7e, // 68
0x7f, 0x40, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7f, // 69
0x7f, 0x40, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, // 70
0x1e, 0x21, 0x40, 0x40, 0x40, 0x47, 0x41, 0x21, 0x1e, // 71
0x41, 0x41, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, 0x41, // 72
0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, // 73
0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, // 74
0x41, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x41, // 75
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f, // 76
0x41, 0x63, 0x55, 0x49, 0x49, 0x41, 0x41, 0x41, 0x41, // 77
0x41, 0x61, 0x51, 0x49, 0x45, 0x43, 0x41, 0x41, 0x41, // 78
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, // 79
0x3e, 0x41, 0x41, 0x1d, 0x55, 0x5e, 0x40, 0x40, 0x3e, /* 64 */
0x1c, 0x22, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, 0x41, /* 65 */
0x7e, 0x21, 0x21, 0x21, 0x3e, 0x21, 0x21, 0x21, 0x7e, /* 66 */
0x1e, 0x21, 0x40, 0x40, 0x40, 0x40, 0x40, 0x21, 0x1e, /* 67 */
0x7e, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x7e, /* 68 */
0x7f, 0x40, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x7f, /* 69 */
0x7f, 0x40, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x40, /* 70 */
0x1e, 0x21, 0x40, 0x40, 0x40, 0x47, 0x41, 0x21, 0x1e, /* 71 */
0x41, 0x41, 0x41, 0x41, 0x7f, 0x41, 0x41, 0x41, 0x41, /* 72 */
0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, /* 73 */
0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x38, /* 74 */
0x41, 0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x41, /* 75 */
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f, /* 76 */
0x41, 0x63, 0x55, 0x49, 0x49, 0x41, 0x41, 0x41, 0x41, /* 77 */
0x41, 0x61, 0x51, 0x49, 0x45, 0x43, 0x41, 0x41, 0x41, /* 78 */
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, /* 79 */
0x7e, 0x41, 0x41, 0x41, 0x7e, 0x40, 0x40, 0x40, 0x40, // 80
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x45, 0x22, 0x1d, // 81
0x7e, 0x41, 0x41, 0x41, 0x7e, 0x48, 0x44, 0x42, 0x41, // 82
0x3e, 0x41, 0x40, 0x40, 0x3e, 0x01, 0x01, 0x41, 0x3e, // 83
0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, // 84
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, // 85
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x14, 0x08, // 86
0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x63, 0x41, // 87
0x41, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x41, // 88
0x41, 0x41, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, // 89
0x7f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7f, // 90
0x1e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1e, // 91
0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, // 92
0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, // 93
0x3e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 94
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, // 95
0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 96
0x00, 0x00, 0x00, 0x1e, 0x22, 0x42, 0x41, 0x46, 0x3a, // 97
0x40, 0x40, 0x40, 0x5c, 0x62, 0x42, 0x42, 0x62, 0x5c, // 98
0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x42, 0x3c, // 99
0x02, 0x02, 0x02, 0x3a, 0x46, 0x42, 0x42, 0x46, 0x3a, // 100
0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x3e, // 101
0x0c, 0x12, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, // 102
0xba, 0x46, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x42, 0x3c, // 103
0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, // 104
0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, // 105
0x82, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x3c, // 106
0x40, 0x40, 0x40, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, // 107
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, // 108
0x00, 0x00, 0x00, 0x76, 0x49, 0x49, 0x49, 0x49, 0x49, // 109
0x00, 0x00, 0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, // 110
0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, // 111
0x7e, 0x41, 0x41, 0x41, 0x7e, 0x40, 0x40, 0x40, 0x40, /* 80 */
0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x45, 0x22, 0x1d, /* 81 */
0x7e, 0x41, 0x41, 0x41, 0x7e, 0x48, 0x44, 0x42, 0x41, /* 82 */
0x3e, 0x41, 0x40, 0x40, 0x3e, 0x01, 0x01, 0x41, 0x3e, /* 83 */
0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, /* 84 */
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, /* 85 */
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x22, 0x14, 0x08, /* 86 */
0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x55, 0x63, 0x41, /* 87 */
0x41, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x41, /* 88 */
0x41, 0x41, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, /* 89 */
0x7f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7f, /* 90 */
0x1e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1e, /* 91 */
0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, /* 92 */
0x3c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x3c, /* 93 */
0x3e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 94 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, /* 95 */
0xdc, 0x62, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x40, 0x40, // 112
0xba, 0x46, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02, 0x02, // 113
0x00, 0x00, 0x00, 0x5c, 0x62, 0x40, 0x40, 0x40, 0x40, // 114
0x00, 0x00, 0x00, 0x3c, 0x42, 0x30, 0x0c, 0x42, 0x3c, // 115
0x00, 0x10, 0x10, 0x7c, 0x10, 0x01, 0x10, 0x12, 0x0c, // 116
0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, // 117
0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x28, 0x10, // 118
0x00, 0x00, 0x00, 0x41, 0x49, 0x49, 0x49, 0x49, 0x36, // 119
0x00, 0x00, 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, // 120
0xc2, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x42, 0x3c, // 121
0x00, 0x00, 0x00, 0x7e, 0x04, 0x08, 0x10, 0x20, 0x7e, // 122
0x0e, 0x10, 0x10, 0x10, 0x20, 0x10, 0x10, 0x10, 0x0e, // 123
0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, // 124
0x38, 0x04, 0x04, 0x04, 0x02, 0x04, 0x04, 0x04, 0x38, // 125
0x30, 0x49, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 126
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f // 127
0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 96 */
0x00, 0x00, 0x00, 0x1e, 0x22, 0x42, 0x41, 0x46, 0x3a, /* 97 */
0x40, 0x40, 0x40, 0x5c, 0x62, 0x42, 0x42, 0x62, 0x5c, /* 98 */
0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x42, 0x3c, /* 99 */
0x02, 0x02, 0x02, 0x3a, 0x46, 0x42, 0x42, 0x46, 0x3a, /* 100 */
0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x3e, /* 101 */
0x0c, 0x12, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, /* 102 */
0xba, 0x46, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x42, 0x3c, /* 103 */
0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, /* 104 */
0x00, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, /* 105 */
0x82, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x3c, /* 106 */
0x40, 0x40, 0x40, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, /* 107 */
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, /* 108 */
0x00, 0x00, 0x00, 0x76, 0x49, 0x49, 0x49, 0x49, 0x49, /* 109 */
0x00, 0x00, 0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, /* 110 */
0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, /* 111 */
0xdc, 0x62, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x40, 0x40, /* 112 */
0xba, 0x46, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02, 0x02, /* 113 */
0x00, 0x00, 0x00, 0x5c, 0x62, 0x40, 0x40, 0x40, 0x40, /* 114 */
0x00, 0x00, 0x00, 0x3c, 0x42, 0x30, 0x0c, 0x42, 0x3c, /* 115 */
0x00, 0x10, 0x10, 0x7c, 0x10, 0x01, 0x10, 0x12, 0x0c, /* 116 */
0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, /* 117 */
0x00, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x28, 0x10, /* 118 */
0x00, 0x00, 0x00, 0x41, 0x49, 0x49, 0x49, 0x49, 0x36, /* 119 */
0x00, 0x00, 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, /* 120 */
0xc2, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x42, 0x3c, /* 121 */
0x00, 0x00, 0x00, 0x7e, 0x04, 0x08, 0x10, 0x20, 0x7e, /* 122 */
0x0e, 0x10, 0x10, 0x10, 0x20, 0x10, 0x10, 0x10, 0x0e, /* 123 */
0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, /* 124 */
0x38, 0x04, 0x04, 0x04, 0x02, 0x04, 0x04, 0x04, 0x38, /* 125 */
0x30, 0x49, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 126 */
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f /* 127 */
};
#endif

View File

@@ -1,41 +1,41 @@
/*
This is the core graphics library for all our displays, providing a common
set of graphics primitives (points, lines, circles, etc.). It needs to be
paired with a hardware-specific library for each display device we carry
(to handle the lower-level functions).
Adafruit invests time and resources providing this open source code, please
support Adafruit & open-source hardware by purchasing products from Adafruit!
Copyright (c) 2013 Adafruit Industries. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*
* Modified the AdaFruit library to be a C library, changed the font and
* generally munged it in a variety of ways, creating a reasonably quick
* and dirty way to put something "interesting" on the LCD display.
* --Chuck McManis (2013, 2014)
*
*/
* This is the core graphics library for all our displays, providing a common
* set of graphics primitives (points, lines, circles, etc.). It needs to be
* paired with a hardware-specific library for each display device we carry
* (to handle the lower-level functions).
*
* Adafruit invests time and resources providing this open source code, please
* support Adafruit & open-source hardware by purchasing products from Adafruit!
*
* Copyright (c) 2013 Adafruit Industries. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Modified the AdaFruit library to be a C library, changed the font and
* generally munged it in a variety of ways, creating a reasonably quick
* and dirty way to put something "interesting" on the LCD display.
* --Chuck McManis (2013, 2014)
*
*/
#include <stdint.h>
#include <math.h>
@@ -48,454 +48,497 @@ POSSIBILITY OF SUCH DAMAGE.
struct gfx_state __gfx_state;
void
gfx_drawPixel(int x, int y, uint16_t color) {
if ((x < 0) || (x >= __gfx_state._width) ||
(y < 0) || (y >= __gfx_state._height)) {
return; // off screen so don't draw it
}
(__gfx_state.drawpixel)(x, y, color);
gfx_drawPixel(int x, int y, uint16_t color)
{
if ((x < 0) || (x >= __gfx_state._width) ||
(y < 0) || (y >= __gfx_state._height)) {
return; /* off screen so don't draw it */
}
(__gfx_state.drawpixel)(x, y, color);
}
#define true 1
void
gfx_init(void (*pixel_func)(int, int, uint16_t), int width, int height)
{
__gfx_state._width = width;
__gfx_state._height = height;
__gfx_state.rotation = 0;
__gfx_state.cursor_y = __gfx_state.cursor_x = 0;
__gfx_state.textsize = 1;
__gfx_state.textcolor = 0;
__gfx_state.textbgcolor = 0xFFFF;
__gfx_state.wrap = true;
__gfx_state.drawpixel = pixel_func;
__gfx_state._width = width;
__gfx_state._height = height;
__gfx_state.rotation = 0;
__gfx_state.cursor_y = __gfx_state.cursor_x = 0;
__gfx_state.textsize = 1;
__gfx_state.textcolor = 0;
__gfx_state.textbgcolor = 0xFFFF;
__gfx_state.wrap = true;
__gfx_state.drawpixel = pixel_func;
}
// Draw a circle outline
/* Draw a circle outline */
void gfx_drawCircle(int16_t x0, int16_t y0, int16_t r,
uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
gfx_drawPixel(x0 , y0+r, color);
gfx_drawPixel(x0 , y0-r, color);
gfx_drawPixel(x0+r, y0 , color);
gfx_drawPixel(x0-r, y0 , color);
gfx_drawPixel(x0 , y0+r, color);
gfx_drawPixel(x0 , y0-r, color);
gfx_drawPixel(x0+r, y0 , color);
gfx_drawPixel(x0-r, y0 , color);
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
gfx_drawPixel(x0 + x, y0 + y, color);
gfx_drawPixel(x0 - x, y0 + y, color);
gfx_drawPixel(x0 + x, y0 - y, color);
gfx_drawPixel(x0 - x, y0 - y, color);
gfx_drawPixel(x0 + y, y0 + x, color);
gfx_drawPixel(x0 - y, y0 + x, color);
gfx_drawPixel(x0 + y, y0 - x, color);
gfx_drawPixel(x0 - y, y0 - x, color);
}
gfx_drawPixel(x0 + x, y0 + y, color);
gfx_drawPixel(x0 - x, y0 + y, color);
gfx_drawPixel(x0 + x, y0 - y, color);
gfx_drawPixel(x0 - x, y0 - y, color);
gfx_drawPixel(x0 + y, y0 + x, color);
gfx_drawPixel(x0 - y, y0 + x, color);
gfx_drawPixel(x0 + y, y0 - x, color);
gfx_drawPixel(x0 - y, y0 - x, color);
}
}
void gfx_drawCircleHelper( int16_t x0, int16_t y0,
int16_t r, uint8_t cornername, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
void gfx_drawCircleHelper(int16_t x0, int16_t y0,
int16_t r, uint8_t cornername, uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
gfx_drawPixel(x0 + x, y0 + y, color);
gfx_drawPixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
gfx_drawPixel(x0 + x, y0 - y, color);
gfx_drawPixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
gfx_drawPixel(x0 - y, y0 + x, color);
gfx_drawPixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
gfx_drawPixel(x0 - y, y0 - x, color);
gfx_drawPixel(x0 - x, y0 - y, color);
}
}
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x4) {
gfx_drawPixel(x0 + x, y0 + y, color);
gfx_drawPixel(x0 + y, y0 + x, color);
}
if (cornername & 0x2) {
gfx_drawPixel(x0 + x, y0 - y, color);
gfx_drawPixel(x0 + y, y0 - x, color);
}
if (cornername & 0x8) {
gfx_drawPixel(x0 - y, y0 + x, color);
gfx_drawPixel(x0 - x, y0 + y, color);
}
if (cornername & 0x1) {
gfx_drawPixel(x0 - y, y0 - x, color);
gfx_drawPixel(x0 - x, y0 - y, color);
}
}
}
void gfx_fillCircle(int16_t x0, int16_t y0, int16_t r,
uint16_t color) {
gfx_drawFastVLine(x0, y0-r, 2*r+1, color);
gfx_fillCircleHelper(x0, y0, r, 3, 0, color);
uint16_t color)
{
gfx_drawFastVLine(x0, y0 - r, 2*r+1, color);
gfx_fillCircleHelper(x0, y0, r, 3, 0, color);
}
// Used to do circles and roundrects
/* Used to do circles and roundrects */
void gfx_fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t cornername, int16_t delta, uint16_t color) {
uint8_t cornername, int16_t delta, uint16_t color)
{
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
while (x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
while (x<y) {
if (f >= 0) {
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x1) {
gfx_drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
gfx_drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
}
if (cornername & 0x2) {
gfx_drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
gfx_drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
}
}
if (cornername & 0x1) {
gfx_drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
gfx_drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
}
if (cornername & 0x2) {
gfx_drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
gfx_drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
}
}
}
// Bresenham's algorithm - thx wikpedia
/* Bresenham's algorithm - thx wikpedia */
void gfx_drawLine(int16_t x0, int16_t y0,
int16_t x1, int16_t y1,
uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
uint16_t color)
{
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
for (; x0<=x1; x0++) {
if (steep) {
gfx_drawPixel(y0, x0, color);
} else {
gfx_drawPixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
for (; x0 <= x1; x0++) {
if (steep) {
gfx_drawPixel(y0, x0, color);
} else {
gfx_drawPixel(x0, y0, color);
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
}
}
}
// Draw a rectangle
/* Draw a rectangle */
void gfx_drawRect(int16_t x, int16_t y,
int16_t w, int16_t h,
uint16_t color) {
gfx_drawFastHLine(x, y, w, color);
gfx_drawFastHLine(x, y+h-1, w, color);
gfx_drawFastVLine(x, y, h, color);
gfx_drawFastVLine(x+w-1, y, h, color);
int16_t w, int16_t h,
uint16_t color)
{
gfx_drawFastHLine(x, y, w, color);
gfx_drawFastHLine(x, y + h - 1, w, color);
gfx_drawFastVLine(x, y, h, color);
gfx_drawFastVLine(x + w - 1, y, h, color);
}
void gfx_drawFastVLine(int16_t x, int16_t y,
int16_t h, uint16_t color) {
// Update in subclasses if desired!
gfx_drawLine(x, y, x, y+h-1, color);
int16_t h, uint16_t color)
{
/* Update in subclasses if desired! */
gfx_drawLine(x, y, x, y + h - 1, color);
}
void gfx_drawFastHLine(int16_t x, int16_t y,
int16_t w, uint16_t color) {
// Update in subclasses if desired!
gfx_drawLine(x, y, x+w-1, y, color);
int16_t w, uint16_t color)
{
/* Update in subclasses if desired! */
gfx_drawLine(x, y, x + w - 1, y, color);
}
void gfx_fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
// Update in subclasses if desired!
int16_t i;
for (i=x; i<x+w; i++) {
gfx_drawFastVLine(i, y, h, color);
}
uint16_t color)
{
/* Update in subclasses if desired! */
int16_t i;
for (i = x; i < x + w; i++) {
gfx_drawFastVLine(i, y, h, color);
}
}
void gfx_fillScreen(uint16_t color) {
gfx_fillRect(0, 0, __gfx_state._width, __gfx_state._height, color);
void gfx_fillScreen(uint16_t color)
{
gfx_fillRect(0, 0, __gfx_state._width, __gfx_state._height, color);
}
// Draw a rounded rectangle
/* Draw a rounded rectangle */
void gfx_drawRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
// smarter version
gfx_drawFastHLine(x+r , y , w-2*r, color); // Top
gfx_drawFastHLine(x+r , y+h-1, w-2*r, color); // Bottom
gfx_drawFastVLine(x , y+r , h-2*r, color); // Left
gfx_drawFastVLine(x+w-1, y+r , h-2*r, color); // Right
// draw four corners
gfx_drawCircleHelper(x+r , y+r , r, 1, color);
gfx_drawCircleHelper(x+w-r-1, y+r , r, 2, color);
gfx_drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
gfx_drawCircleHelper(x+r , y+h-r-1, r, 8, color);
int16_t h, int16_t r, uint16_t color)
{
/* smarter version */
gfx_drawFastHLine(x + r , y , w - 2 * r, color); /* Top */
gfx_drawFastHLine(x + r , y + h - 1, w - 2 * r, color); /* Bottom */
gfx_drawFastVLine(x , y + r , h - 2 * r, color); /* Left */
gfx_drawFastVLine(x + w - 1, y + r , h - 2 * r, color); /* Right */
/* draw four corners */
gfx_drawCircleHelper(x + r , y + r , r, 1, color);
gfx_drawCircleHelper(x + w - r - 1, y + r , r, 2, color);
gfx_drawCircleHelper(x + w - r - 1, y + h - r - 1, r, 4, color);
gfx_drawCircleHelper(x + r , y + h - r - 1, r, 8, color);
}
// Fill a rounded rectangle
/* Fill a rounded rectangle */
void gfx_fillRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
// smarter version
gfx_fillRect(x+r, y, w-2*r, h, color);
int16_t h, int16_t r, uint16_t color) {
/* smarter version */
gfx_fillRect(x + r, y, w - 2 * r, h, color);
// draw four corners
gfx_fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
gfx_fillCircleHelper(x+r , y+r, r, 2, h-2*r-1, color);
/* draw four corners */
gfx_fillCircleHelper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
gfx_fillCircleHelper(x + r , y + r, r, 2, h - 2 * r - 1, color);
}
// Draw a triangle
/* Draw a triangle */
void gfx_drawTriangle(int16_t x0, int16_t y0,
int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color) {
gfx_drawLine(x0, y0, x1, y1, color);
gfx_drawLine(x1, y1, x2, y2, color);
gfx_drawLine(x2, y2, x0, y0, color);
int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color)
{
gfx_drawLine(x0, y0, x1, y1, color);
gfx_drawLine(x1, y1, x2, y2, color);
gfx_drawLine(x2, y2, x0, y0, color);
}
// Fill a triangle
void gfx_fillTriangle ( int16_t x0, int16_t y0,
int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color) {
/* Fill a triangle */
void gfx_fillTriangle(int16_t x0, int16_t y0,
int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color)
{
int16_t a, b, y, last;
int16_t a, b, y, last;
/* Sort coordinates by Y order (y2 >= y1 >= y0) */
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
if (y1 > y2) {
swap(y2, y1); swap(x2, x1);
}
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
if (y1 > y2) {
swap(y2, y1); swap(x2, x1);
}
if (y0 > y1) {
swap(y0, y1); swap(x0, x1);
}
/* Handle awkward all-on-same-line case as its own thing */
if (y0 == y2) {
a = b = x0;
if (x1 < a) {
a = x1;
} else if (x1 > b) {
b = x1;
}
if (x2 < a) {
a = x2;
} else if (x2 > b) {
b = x2;
}
gfx_drawFastHLine(a, y0, b - a + 1, color);
return;
}
if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
a = b = x0;
if(x1 < a) a = x1;
else if(x1 > b) b = x1;
if(x2 < a) a = x2;
else if(x2 > b) b = x2;
gfx_drawFastHLine(a, y0, b-a+1, color);
return;
}
int16_t
dx01 = x1 - x0,
dy01 = y1 - y0,
dx02 = x2 - x0,
dy02 = y2 - y0,
dx12 = x2 - x1,
dy12 = y2 - y1,
sa = 0,
sb = 0;
int16_t
dx01 = x1 - x0,
dy01 = y1 - y0,
dx02 = x2 - x0,
dy02 = y2 - y0,
dx12 = x2 - x1,
dy12 = y2 - y1,
sa = 0,
sb = 0;
/* For upper part of triangle, find scanline crossings for segments
* 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
* is included here (and second loop will be skipped, avoiding a /0
* error there), otherwise scanline y1 is skipped here and handled
* in the second loop...which also avoids a /0 error here if y0=y1
* (flat-topped triangle).
*/
if (y1 == y2) {
last = y1; /* Include y1 scanline */
} else {
last = y1 - 1; /* Skip it */
}
// For upper part of triangle, find scanline crossings for segments
// 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
// is included here (and second loop will be skipped, avoiding a /0
// error there), otherwise scanline y1 is skipped here and handled
// in the second loop...which also avoids a /0 error here if y0=y1
// (flat-topped triangle).
if(y1 == y2) last = y1; // Include y1 scanline
else last = y1-1; // Skip it
for (y = y0; y <= last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) {
swap(a, b);
}
gfx_drawFastHLine(a, y, b - a + 1, color);
}
for(y=y0; y<=last; y++) {
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
/* longhand:
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b) swap(a,b);
gfx_drawFastHLine(a, y, b-a+1, color);
}
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for(; y<=y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b) swap(a,b);
gfx_drawFastHLine(a, y, b-a+1, color);
}
/* For lower part of triangle, find scanline crossings for segments
* 0-2 and 1-2. This loop is skipped if y1=y2.
*/
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for (; y <= y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
/* longhand:
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if (a > b) {
swap(a, b);
}
gfx_drawFastHLine(a, y, b - a + 1, color);
}
}
void gfx_drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h,
uint16_t color) {
const uint8_t *bitmap, int16_t w, int16_t h,
uint16_t color)
{
int16_t i, j, byteWidth = (w + 7) / 8;
int16_t i, j, byteWidth = (w + 7) / 8;
for(j=0; j<h; j++) {
for(i=0; i<w; i++ ) {
if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7))) {
gfx_drawPixel(x+i, y+j, color);
}
}
}
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (pgm_read_byte(bitmap + j * byteWidth + i / 8) &
(128 >> (i & 7))) {
gfx_drawPixel(x + i, y + j, color);
}
}
}
}
void gfx_write(uint8_t c) {
if (c == '\n') {
__gfx_state.cursor_y += __gfx_state.textsize*12;
__gfx_state.cursor_x = 0;
} else if (c == '\r') {
// skip em
} else {
gfx_drawChar(__gfx_state.cursor_x, __gfx_state.cursor_y,
c, __gfx_state.textcolor, __gfx_state.textbgcolor,
__gfx_state.textsize);
__gfx_state.cursor_x += __gfx_state.textsize*8;
if (__gfx_state.wrap && (__gfx_state.cursor_x > (__gfx_state._width - __gfx_state.textsize*8))) {
__gfx_state.cursor_y += __gfx_state.textsize*12;
__gfx_state.cursor_x = 0;
}
}
void gfx_write(uint8_t c)
{
if (c == '\n') {
__gfx_state.cursor_y += __gfx_state.textsize * 12;
__gfx_state.cursor_x = 0;
} else if (c == '\r') {
/* skip em */
} else {
gfx_drawChar(__gfx_state.cursor_x, __gfx_state.cursor_y,
c, __gfx_state.textcolor, __gfx_state.textbgcolor,
__gfx_state.textsize);
__gfx_state.cursor_x += __gfx_state.textsize * 8;
if (__gfx_state.wrap &&
(__gfx_state.cursor_x > (__gfx_state._width -
__gfx_state.textsize*8))) {
__gfx_state.cursor_y += __gfx_state.textsize * 12;
__gfx_state.cursor_x = 0;
}
}
}
void gfx_puts(char *s) {
while (*s) {
gfx_write(*s);
s++;
}
void gfx_puts(char *s)
{
while (*s) {
gfx_write(*s);
s++;
}
}
// Draw a character
/* Draw a character */
void gfx_drawChar(int16_t x, int16_t y, unsigned char c,
uint16_t color, uint16_t bg, uint8_t size) {
uint16_t color, uint16_t bg, uint8_t size)
{
int8_t i, j, line;
int8_t descender;
unsigned const char *glyph;
int8_t i, j, line;
int8_t descender;
unsigned const char *glyph;
glyph = &mcm_font[(c & 0x7f) * 9];
glyph = &mcm_font[(c & 0x7f) * 9];
descender = (*glyph & 0x80) != 0;
descender = (*glyph & 0x80) != 0;
for (i=0; i<12; i++ ) {
line = 0x00;
if ( descender ) {
if (i > 2) {
line = *(glyph + (i - 3));
}
} else {
if (i < 9) {
line = *(glyph + i);
}
}
line &= 0x7f;
for (j = 0; j<8; j++) {
if (line & 0x80) {
if (size == 1) // default size
gfx_drawPixel(x+j, y+i, color);
else { // big size
gfx_fillRect(x+(j*size), y+(i*size), size, size, color);
}
} else if (bg != color) {
if (size == 1) // default size
gfx_drawPixel(x+j, y+i, bg);
else { // big size
gfx_fillRect(x+j*size, y+i*size, size, size, bg);
}
}
line <<= 1;
}
}
for (i = 0; i < 12; i++) {
line = 0x00;
if (descender) {
if (i > 2) {
line = *(glyph + (i - 3));
}
} else {
if (i < 9) {
line = *(glyph + i);
}
}
line &= 0x7f;
for (j = 0; j < 8; j++) {
if (line & 0x80) {
if (size == 1) /* default size */
gfx_drawPixel(x+j, y+i, color);
else { /* big size */
gfx_fillRect(x+(j*size), y+(i*size),
size, size, color);
}
} else if (bg != color) {
if (size == 1) /* default size */
gfx_drawPixel(x+j, y+i, bg);
else { /* big size */
gfx_fillRect(x+j*size, y+i*size,
size, size, bg);
}
}
line <<= 1;
}
}
}
void gfx_setCursor(int16_t x, int16_t y) {
__gfx_state.cursor_x = x;
__gfx_state.cursor_y = y;
void gfx_setCursor(int16_t x, int16_t y)
{
__gfx_state.cursor_x = x;
__gfx_state.cursor_y = y;
}
void gfx_setTextSize(uint8_t s) {
__gfx_state.textsize = (s > 0) ? s : 1;
void gfx_setTextSize(uint8_t s)
{
__gfx_state.textsize = (s > 0) ? s : 1;
}
void gfx_setTextColor(uint16_t c, uint16_t b) {
__gfx_state.textcolor = c;
__gfx_state.textbgcolor = b;
void gfx_setTextColor(uint16_t c, uint16_t b)
{
__gfx_state.textcolor = c;
__gfx_state.textbgcolor = b;
}
void gfx_setTextWrap(uint8_t w) {
__gfx_state.wrap = w;
void gfx_setTextWrap(uint8_t w)
{
__gfx_state.wrap = w;
}
uint8_t gfx_getRotation(void) {
return __gfx_state.rotation;
uint8_t gfx_getRotation(void)
{
return __gfx_state.rotation;
}
void gfx_setRotation(uint8_t x) {
__gfx_state.rotation = (x & 3);
switch(__gfx_state.rotation) {
case 0:
case 2:
__gfx_state._width = GFX_WIDTH;
__gfx_state._height = GFX_HEIGHT;
break;
case 1:
case 3:
__gfx_state._width = GFX_HEIGHT;
__gfx_state._height = GFX_WIDTH;
break;
}
void gfx_setRotation(uint8_t x)
{
__gfx_state.rotation = (x & 3);
switch (__gfx_state.rotation) {
case 0:
case 2:
__gfx_state._width = GFX_WIDTH;
__gfx_state._height = GFX_HEIGHT;
break;
case 1:
case 3:
__gfx_state._width = GFX_HEIGHT;
__gfx_state._height = GFX_WIDTH;
break;
}
}
// Return the size of the display (per current rotation)
uint16_t gfx_width(void) {
return __gfx_state._width;
}
uint16_t gfx_height(void) {
return __gfx_state._height;
/* Return the size of the display (per current rotation) */
uint16_t gfx_width(void)
{
return __gfx_state._width;
}
uint16_t gfx_height(void)
{
return __gfx_state._height;
}

View File

@@ -1,4 +1,4 @@
/*
/*
* A simple port of the AdaFruit minimal graphics code to my
* demo code.
*/
@@ -9,7 +9,8 @@
#define swap(a, b) { int16_t t = a; a = b; b = t; }
void gfx_drawPixel(int x, int y, uint16_t color);
void gfx_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void gfx_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
uint16_t color);
void gfx_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void gfx_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void gfx_drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
@@ -17,25 +18,25 @@ void gfx_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void gfx_fillScreen(uint16_t color);
void gfx_drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void gfx_drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
uint16_t color);
void gfx_drawCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t cornername, uint16_t color);
void gfx_fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void gfx_init(void (*draw)(int, int, uint16_t), int, int);
void gfx_fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
int16_t delta, uint16_t color);
void gfx_fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t cornername, int16_t delta, uint16_t color);
void gfx_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color);
int16_t x2, int16_t y2, uint16_t color);
void gfx_fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color);
int16_t x2, int16_t y2, uint16_t color);
void gfx_drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color);
int16_t radius, uint16_t color);
void gfx_fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color);
int16_t radius, uint16_t color);
void gfx_drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap,
int16_t w, int16_t h, uint16_t color);
int16_t w, int16_t h, uint16_t color);
void gfx_drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
uint16_t bg, uint8_t size);
uint16_t bg, uint8_t size);
void gfx_setCursor(int16_t x, int16_t y);
void gfx_setTextColor(uint16_t c, uint16_t bg);
void gfx_setTextSize(uint8_t s);
@@ -53,11 +54,11 @@ uint8_t gfx_getRotation(void);
#define GFX_HEIGHT 240
struct gfx_state {
int16_t _width, _height, cursor_x, cursor_y;
uint16_t textcolor, textbgcolor;
uint8_t textsize, rotation;
uint8_t wrap;
void (*drawpixel)(int, int, uint16_t);
int16_t _width, _height, cursor_x, cursor_y;
uint16_t textcolor, textbgcolor;
uint8_t textsize, rotation;
uint8_t wrap;
void (*drawpixel)(int, int, uint16_t);
};
extern struct gfx_state __gfx_state;
@@ -73,4 +74,4 @@ extern struct gfx_state __gfx_state;
#define GFX_COLOR_CYAN 0x7FFF
#define GFX_COLOR_YELLOW 0xFFE0
#endif // _ADAFRUIT_GFX_H
#endif /* _ADAFRUIT_GFX_H */

View File

@@ -32,7 +32,8 @@
* This is our example, the heavy lifing is actually in lcd-spi.c but
* this drives that code.
*/
int main(void) {
int main(void)
{
int p1, p2, p3;
clock_setup();
@@ -42,7 +43,7 @@ int main(void) {
console_puts("LCD Initialized\n");
console_puts("Should have a checker pattern, press any key to proceed\n");
msleep(2000);
// (void) console_getc(1);
/* (void) console_getc(1); */
gfx_init(lcd_draw_pixel, 240, 320);
gfx_fillScreen(LCD_GREY);
gfx_fillRoundRect(10, 10, 220, 220, 5, LCD_WHITE);
@@ -62,7 +63,7 @@ int main(void) {
console_puts("Now it has a bit of structured graphics.\n");
console_puts("Press a key for some simple animation.\n");
msleep(2000);
// (void) console_getc(1);
/* (void) console_getc(1); */
gfx_setTextColor(LCD_YELLOW, LCD_BLACK);
gfx_setTextSize(3);
p1 = 0;
@@ -72,17 +73,17 @@ int main(void) {
gfx_fillScreen(LCD_BLACK);
gfx_setCursor(15, 36);
gfx_puts("PLANETS!");
gfx_fillCircle( 120, 160, 40, LCD_YELLOW);
gfx_drawCircle( 120, 160, 55, LCD_GREY);
gfx_drawCircle( 120, 160, 75, LCD_GREY);
gfx_drawCircle( 120, 160, 100, LCD_GREY);
gfx_fillCircle(120, 160, 40, LCD_YELLOW);
gfx_drawCircle(120, 160, 55, LCD_GREY);
gfx_drawCircle(120, 160, 75, LCD_GREY);
gfx_drawCircle(120, 160, 100, LCD_GREY);
gfx_fillCircle( 120 + (sin(d2r(p1)) * 55),
160 + (cos(d2r(p1)) * 55), 5, LCD_RED);
gfx_fillCircle( 120 + (sin(d2r(p2)) * 75),
160 + (cos(d2r(p2)) * 75), 10, LCD_WHITE);
gfx_fillCircle( 120 + (sin(d2r(p3)) * 100),
160 + (cos(d2r(p3)) * 100), 8, LCD_BLUE);
gfx_fillCircle(120 + (sin(d2r(p1)) * 55),
160 + (cos(d2r(p1)) * 55), 5, LCD_RED);
gfx_fillCircle(120 + (sin(d2r(p2)) * 75),
160 + (cos(d2r(p2)) * 75), 10, LCD_WHITE);
gfx_fillCircle(120 + (sin(d2r(p3)) * 100),
160 + (cos(d2r(p3)) * 100), 8, LCD_BLUE);
p1 = (p1 + 3) % 360;
p2 = (p2 + 2) % 360;
p3 = (p3 + 1) % 360;

View File

@@ -48,8 +48,9 @@ uint16_t *display_frame;
* of the word to store, and puts in the value we pass to it.
*/
void
lcd_draw_pixel(int x, int y, uint16_t color) {
*(cur_frame + x + y * LCD_WIDTH) = color;
lcd_draw_pixel(int x, int y, uint16_t color)
{
*(cur_frame + x + y * LCD_WIDTH) = color;
}
/*
@@ -72,9 +73,9 @@ lcd_draw_pixel(int x, int y, uint16_t color) {
* initialization sequence for the display.
*/
struct tft_command {
uint16_t delay; // If you need a delay after
uint8_t cmd; // command to send
uint8_t n_args; // How many arguments it has
uint16_t delay; /* If you need a delay after */
uint8_t cmd; /* command to send */
uint8_t n_args; /* How many arguments it has */
};
@@ -90,21 +91,22 @@ static void lcd_command(uint8_t cmd, int delay, int n_args,
* sends those along too.
*/
static void
lcd_command(uint8_t cmd, int delay, int n_args, const uint8_t *args) {
lcd_command(uint8_t cmd, int delay, int n_args, const uint8_t *args)
{
int i;
gpio_clear(GPIOC, GPIO2); // Select the LCD
gpio_clear(GPIOC, GPIO2); /* Select the LCD */
(void) spi_xfer(LCD_SPI, cmd);
if (n_args) {
gpio_set(GPIOD, GPIO13); // Set the D/CX pin
gpio_set(GPIOD, GPIO13); /* Set the D/CX pin */
for (i = 0; i < n_args; i++) {
(void) spi_xfer(LCD_SPI, *(args+i));
}
}
gpio_set(GPIOC, GPIO2); // Turn off chip select
gpio_clear(GPIOD, GPIO13); // always reset D/CX
gpio_set(GPIOC, GPIO2); /* Turn off chip select */
gpio_clear(GPIOD, GPIO13); /* always reset D/CX */
if (delay) {
msleep(delay); // wait, if called for
msleep(delay); /* wait, if called for */
}
}
@@ -122,16 +124,16 @@ static const uint8_t cmd_args[] = {
0x10,
0x45, 0x15,
0x90,
// 0xc8, // original
// 11001000 = MY, MX, BGR
/* 0xc8,*/ /* original */
/* 11001000 = MY, MX, BGR */
0x08,
0xc2,
0x55,
0x0a, 0xa7, 0x27, 0x04,
0x00, 0x00, 0x00, 0xef,
0x00, 0x00, 0x01, 0x3f,
// 0x01, 0x00, 0x06, // original
0x01, 0x00, 0x00, // modified to remove RGB mode
/* 0x01, 0x00, 0x06,*/ /* original */
0x01, 0x00, 0x00, /* modified to remove RGB mode */
0x01,
0x0F, 0x29, 0x24, 0x0C, 0x0E,
0x09, 0x4E, 0x78, 0x3C, 0x09,
@@ -152,30 +154,30 @@ static const uint8_t cmd_args[] = {
* code, the data sheet, and other sources on the web.
*/
const struct tft_command initialization[] = {
{ 0, 0xb1, 2 }, // 0x00, 0x1B,
{ 0, 0xb6, 2 }, // 0x0a, 0xa2,
{ 0, 0xc0, 1 }, // 0x10,
{ 0, 0xc1, 1 }, // 0x10,
{ 0, 0xc5, 2 }, // 0x45, 0x15,
{ 0, 0xc7, 1 }, // 0x90,
{ 0, 0x36, 1 }, // 0xc8,
{ 0, 0xb0, 1 }, // 0xc2,
{ 0, 0x3a, 1 }, // 0x55 **added, pixel format 16 bpp
{ 0, 0xb6, 4 }, // 0x0a, 0xa7, 0x27, 0x04,
{ 0, 0x2A, 4 }, // 0x00, 0x00, 0x00, 0xef,
{ 0, 0x2B, 4 }, // 0x00, 0x00, 0x01, 0x3f,
{ 0, 0xf6, 3 }, // 0x01, 0x00, 0x06,
{ 0, 0xb1, 2 }, /* 0x00, 0x1B, */
{ 0, 0xb6, 2 }, /* 0x0a, 0xa2, */
{ 0, 0xc0, 1 }, /* 0x10, */
{ 0, 0xc1, 1 }, /* 0x10, */
{ 0, 0xc5, 2 }, /* 0x45, 0x15, */
{ 0, 0xc7, 1 }, /* 0x90, */
{ 0, 0x36, 1 }, /* 0xc8, */
{ 0, 0xb0, 1 }, /* 0xc2, */
{ 0, 0x3a, 1 }, /* 0x55 **added, pixel format 16 bpp */
{ 0, 0xb6, 4 }, /* 0x0a, 0xa7, 0x27, 0x04, */
{ 0, 0x2A, 4 }, /* 0x00, 0x00, 0x00, 0xef, */
{ 0, 0x2B, 4 }, /* 0x00, 0x00, 0x01, 0x3f, */
{ 0, 0xf6, 3 }, /* 0x01, 0x00, 0x06, */
{ 200, 0x2c, 0 },
{ 0, 0x26, 1}, // 0x01,
{ 0, 0xe0, 15 }, // 0x0F, 0x29, 0x24, 0x0C, 0x0E,
// 0x09, 0x4E, 0x78, 0x3C, 0x09,
// 0x13, 0x05, 0x17, 0x11, 0x00,
{ 0, 0xe1, 15 }, // 0x00, 0x16, 0x1B, 0x04, 0x11,
// 0x07, 0x31, 0x33, 0x42, 0x05,
// 0x0C, 0x0A, 0x28, 0x2F, 0x0F,
{ 0, 0x26, 1}, /* 0x01, */
{ 0, 0xe0, 15 }, /* 0x0F, 0x29, 0x24, 0x0C, 0x0E, */
/* 0x09, 0x4E, 0x78, 0x3C, 0x09, */
/* 0x13, 0x05, 0x17, 0x11, 0x00, */
{ 0, 0xe1, 15 }, /* 0x00, 0x16, 0x1B, 0x04, 0x11, */
/* 0x07, 0x31, 0x33, 0x42, 0x05, */
/* 0x0C, 0x0A, 0x28, 0x2F, 0x0F, */
{ 200, 0x11, 0 },
{ 0, 0x29, 0 },
{ 0, 0, 0 } // cmd == 0 indicates last command
{ 0, 0, 0 } /* cmd == 0 indicates last command */
};
/* prototype for initialize_display */
@@ -188,7 +190,8 @@ static void initialize_display(const struct tft_command cmds[]);
* the commands it is sending to the console.
*/
static void
initialize_display(const struct tft_command cmds[]) {
initialize_display(const struct tft_command cmds[])
{
int i = 0;
int arg_offset = 0;
int j;
@@ -235,18 +238,19 @@ static void test_image(void);
* white lines. No line on the right edge and bottom of screen.
*/
static void
test_image(void) {
test_image(void)
{
int x, y;
uint16_t pixel;
for (x = 0; x < LCD_WIDTH; x++) {
for (y = 0; y < LCD_HEIGHT; y++) {
pixel = 0; // all black
pixel = 0; /* all black */
if ((x % 16) == 0) {
pixel = 0xffff; // all white
pixel = 0xffff; /* all white */
}
if ((y % 16) == 0) {
pixel = 0xffff; // all white
pixel = 0xffff; /* all white */
}
lcd_draw_pixel(x, y, pixel);
}
@@ -261,7 +265,8 @@ test_image(void) {
* the implementation of SPI and the modules interpretation of
* D/CX line.
*/
void lcd_show_frame(void) {
void lcd_show_frame(void)
{
uint16_t *t;
uint8_t size[4];
@@ -302,7 +307,8 @@ void lcd_show_frame(void) {
* LCD_HEIGHT 320
*/
void
lcd_spi_init(void) {
lcd_spi_init(void)
{
/*
* Set up the GPIO lines for the SPI port and
@@ -348,7 +354,8 @@ lcd_spi_init(void) {
* number on the console.
*/
int
print_decimal(int num) {
print_decimal(int num)
{
int ndx = 0;
char buf[10];
int len = 0;
@@ -372,7 +379,7 @@ print_decimal(int num) {
console_putc(buf[ndx--]);
len++;
}
return len; // number of characters printed
return len; /* number of characters printed */
}
/*
@@ -380,7 +387,8 @@ print_decimal(int num) {
*
* Very simple routine for printing out hex constants.
*/
static int print_hex(int v) {
static int print_hex(int v)
{
int ndx = 0;
char buf[10];
int len;
@@ -388,7 +396,7 @@ static int print_hex(int v) {
buf[ndx++] = '\000';
do {
char c = v & 0xf;
buf[ndx++] = (c > 9) ? '7'+ c : '0' + c;
buf[ndx++] = (c > 9) ? '7' + c : '0' + c;
v = (v >> 4) & 0x0fffffff;
} while (v != 0);
ndx--;
@@ -398,5 +406,5 @@ static int print_hex(int v) {
console_putc(buf[ndx--]);
len++;
}
return len; // number of characters printed
return len; /* number of characters printed */
}

View File

@@ -31,25 +31,25 @@ void lcd_spi_init(void);
void lcd_show_frame(void);
void lcd_draw_pixel(int x, int y, uint16_t color);
// Color definitions
/* Color definitions */
#define LCD_BLACK 0x0000
#define LCD_BLUE 0x1F00
#define LCD_RED 0x00F8
#define LCD_GREEN 0xE007
#define LCD_CYAN 0xFF07
#define LCD_MAGENTA 0x1FF8
#define LCD_YELLOW 0xE0FF
#define LCD_YELLOW 0xE0FF
#define LCD_WHITE 0xFFFF
#define LCD_GREY 0xc339
/*
* SPI Port and GPIO Defined - for STM32F4-Disco
*/
// #define LCD_RESET PA3 not used
#define LCD_CS PC2 // CH 1
#define LCD_SCK PF7 // CH 2
#define LCD_DC PD13 // CH 4
#define LCD_MOSI PF9 // CH 3
/* #define LCD_RESET PA3 not used */
#define LCD_CS PC2 /* CH 1 */
#define LCD_SCK PF7 /* CH 2 */
#define LCD_DC PD13 /* CH 4 */
#define LCD_MOSI PF9 /* CH 3 */
#define LCD_SPI SPI5

View File

@@ -43,7 +43,7 @@ static struct {
GPIO11 | GPIO12 | GPIO13 | GPIO14 | GPIO15 },
{GPIOF, GPIO0 | GPIO1 | GPIO2 | GPIO3 | GPIO4 | GPIO5 | GPIO11 |
GPIO12 | GPIO13 | GPIO14 | GPIO15 },
{GPIOG, GPIO0 | GPIO1 | GPIO4 | GPIO5 |GPIO8 | GPIO15}
{GPIOG, GPIO0 | GPIO1 | GPIO4 | GPIO5 | GPIO8 | GPIO15}
};
static struct sdram_timing timing = {
@@ -62,7 +62,7 @@ static struct sdram_timing timing = {
void
sdram_init(void) {
int i;
uint32_t cr_tmp, tr_tmp; // control, timing registers
uint32_t cr_tmp, tr_tmp; /* control, timing registers */
/*
* First all the GPIO pins that end up as SDRAM pins
@@ -75,10 +75,10 @@ sdram_init(void) {
rcc_periph_clock_enable(RCC_GPIOG);
for (i = 0; i < 6; i++) {
gpio_mode_setup(sdram_pins[i].gpio, GPIO_MODE_AF, GPIO_PUPD_NONE,
sdram_pins[i].pins);
gpio_mode_setup(sdram_pins[i].gpio, GPIO_MODE_AF,
GPIO_PUPD_NONE, sdram_pins[i].pins);
gpio_set_output_options(sdram_pins[i].gpio, GPIO_OTYPE_PP,
GPIO_OSPEED_50MHZ, sdram_pins[i].pins);
GPIO_OSPEED_50MHZ, sdram_pins[i].pins);
gpio_set_af(sdram_pins[i].gpio, GPIO_AF12, sdram_pins[i].pins);
}
@@ -107,7 +107,7 @@ sdram_init(void) {
*/
FMC_SDCR1 |= (cr_tmp & FMC_SDCR_DNC_MASK);
FMC_SDCR2 = cr_tmp;
tr_tmp = sdram_timing(&timing);
FMC_SDTR1 |= (tr_tmp & FMC_SDTR_DNC_MASK);
FMC_SDTR2 = tr_tmp;
@@ -119,12 +119,12 @@ sdram_init(void) {
* - Load the Mode Register
*/
sdram_command(SDRAM_BANK2, SDRAM_CLK_CONF, 1, 0);
msleep(1); // sleep at least 100uS
msleep(1); /* sleep at least 100uS */
sdram_command(SDRAM_BANK2, SDRAM_PALL, 1, 0);
sdram_command(SDRAM_BANK2, SDRAM_AUTO_REFRESH, 4, 0);
tr_tmp = SDRAM_MODE_BURST_LENGTH_2 |
SDRAM_MODE_BURST_TYPE_SEQUENTIAL |
SDRAM_MODE_CAS_LATENCY_3 |
SDRAM_MODE_CAS_LATENCY_3 |
SDRAM_MODE_OPERATING_MODE_STANDARD |
SDRAM_MODE_WRITEBURST_MODE_SINGLE;
sdram_command(SDRAM_BANK2, SDRAM_LOAD_MODE, 1, tr_tmp);