initial version for an 3 line LCD

This commit is contained in:
Martin Mueller
2010-10-30 22:01:09 +00:00
parent 274284dc7a
commit 9e8cdeb3ec
5 changed files with 313 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE module SYSTEM "module.dtd">
<!-- Driver for the EA DOG-M163 LCD (SPI) -->
<module name="lcd_dogm" dir="display">
<header>
<file name="lcd_dogm.h"/>
</header>
<init fun="lcd_dogm_init()"/>
<makefile target="ap">
<file_hw name="lcd_dogm_hw.c"/>
<file name="lcd_dogm.c"/>
</makefile>
</module>
@@ -0,0 +1,98 @@
/*
* $Id$
*
* Copyright (C) 2009 ENAC
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "LPC21xx.h"
#include "interrupt_hw.h"
#include "lcd_dogm_hw.h"
static void SPI1_ISR(void) __attribute__((naked));
#define PINSEL1_SCK (2 << 2)
#define PINSEL1_MOSI (2 << 6)
#define PINSEL1_SSEL (2 << 8)
/* SSPCR0 settings */
#define SSP_DSS 0x07 << 0 /* data size : 8 bits */
#define SSP_FRF 0x00 << 4 /* frame format : SPI */
#define SSP_CPOL 0x01 << 6 /* clock polarity : idle high */
#define SSP_CPHA 0x01 << 7 /* clock phase : low->high */
#define SSP_SCR 0x1F << 8 /* serial clock rate : 29.3kHz, SSP input clock / 16 */
/* SSPCR1 settings */
#define SSP_LBM 0x00 << 0 /* loopback mode : disabled */
#define SSP_SSE 0x00 << 1 /* SSP enable : disabled */
#define SSP_MS 0x00 << 2 /* master slave mode : master */
#define SSP_SOD 0x00 << 3 /* slave output disable : don't care when master */
#ifndef SSPCPSR_VAL
#define SSPCPSR_VAL 0x04
#endif
void lcd_spi_tx(uint8_t data) {
SpiClearRti();
SpiEnableRti();
SpiEnable();
SSPDR = data;
}
void lcd_dogm_init_hw( void ) {
/* setup pins for SSP (SCK, MOSI) */
PINSEL1 |= PINSEL1_SCK | PINSEL1_MOSI;
/* setup SSP */
SSPCR0 = SSP_DSS | SSP_FRF | SSP_CPOL | SSP_CPHA | SSP_SCR;
SSPCR1 = SSP_LBM | SSP_MS | SSP_SOD;
SSPCPSR = SSPCPSR_VAL; /* Prescaler */
/* SS, RS pin is output */
SetBit(LCDDOGM_SS_IODIR, LCDDOGM_SS_PIN);
SetBit(LCDDOGM_RS_IODIR, LCDDOGM_RS_PIN);
/* unselected lcd */
lcddogmUnselect();
/* Configure interrupt vector for SPI */
VICIntSelect &= ~VIC_BIT(VIC_SPI1); /* SPI1 selected as IRQ */
VICIntEnable = VIC_BIT(VIC_SPI1); /* SPI1 interrupt enabled */
VICVectCntl7 = VIC_ENABLE | VIC_SPI1;
VICVectAddr7 = (uint32_t)SPI1_ISR; /* address of the ISR */
}
void SPI1_ISR(void) {
ISR_ENTRY();
while (bit_is_set(SSPSR, RNE)) {
uint16_t foo __attribute__ ((unused));
foo = SSPDR;
}
SpiClearRti(); /* clear interrupt */
SpiDisableRti();
SpiDisable ();
lcddogmUnselect();
VICVectAddr = 0x00000000; /* clear this interrupt from the VIC */
ISR_EXIT();
}
@@ -0,0 +1,48 @@
#ifndef LCD_DOGM_HW_H
#define LCD_DOGM_HW_H
#include <stdbool.h>
#include "std.h"
#include "spi_hw.h"
#include "led.h"
#define LCDDOGM_SS_PORT 0
#define LCDDOGM_SS_PIN 20
#define LCDDOGM_RS_PORT 0
#define LCDDOGM_RS_PIN 16
#define LCDDOGM_IO__(port, reg) IO ## port ## reg
#define LCDDOGM_IO_(port, reg) LCDDOGM_IO__(port, reg)
#define LCDDOGM_SS_IOCLR LCDDOGM_IO_(LCDDOGM_SS_PORT, CLR)
#define LCDDOGM_SS_IODIR LCDDOGM_IO_(LCDDOGM_SS_PORT, DIR)
#define LCDDOGM_SS_IOSET LCDDOGM_IO_(LCDDOGM_SS_PORT, SET)
#define LCDDOGM_RS_IOCLR LCDDOGM_IO_(LCDDOGM_RS_PORT, CLR)
#define LCDDOGM_RS_IODIR LCDDOGM_IO_(LCDDOGM_RS_PORT, DIR)
#define LCDDOGM_RS_IOSET LCDDOGM_IO_(LCDDOGM_RS_PORT, SET)
#define lcddogmSelect() { \
SetBit(LCDDOGM_SS_IOCLR, LCDDOGM_SS_PIN); \
}
#define lcddogmUnselect() { \
SetBit(LCDDOGM_SS_IOSET, LCDDOGM_SS_PIN); \
}
#define lcddogmCmdMode() { \
SetBit(LCDDOGM_RS_IOCLR, LCDDOGM_RS_PIN); \
}
#define lcddogmDataMode() { \
SetBit(LCDDOGM_RS_IOSET, LCDDOGM_RS_PIN); \
}
extern void lcd_spi_tx(uint8_t data);
extern void lcd_dogm_init_hw( void );
#endif /* LCD_DOGM_HW_H */
+127
View File
@@ -0,0 +1,127 @@
/*
* $Id$
*
* Copyright (C) 2010 Martin Mueller
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/*
initial version, needs polishing!
3 line LCD at 3.3V
EA DOGM163 <-> LPC2148 SPI1
SI MOSI
CLK SCK
RS DRDY (used to switch cmd/data)
CSB SSEL
*/
#include "display/lcd_dogm_hw.h"
#include "lcd_dogm.h"
void lcd_cmd(uint8_t command) {
uint32_t i;
for (i=0;i<20000;i++);
lcddogmSelect();
lcddogmCmdMode();
lcd_spi_tx(command);
}
void lcd_data(uint8_t data) {
uint32_t i;
for (i=0;i<100000;i++);
lcddogmSelect();
lcddogmDataMode();
lcd_spi_tx(data);
}
void lcd_dogm_init( void ) {
uint32_t i;
for (i=0;i<100000;i++);
lcd_dogm_init_hw();
/* Write configuration */
lcd_cmd(DOGM_FUN_SET_1);
lcd_cmd(DOGM_BIAS_SET);
lcd_cmd(DOGM_PWR_CTRL);
lcd_cmd(DOGM_FOLLOWER);
lcd_cmd(DOGM_CONTRAST);
lcd_cmd(DOGM_DISP_ON);
lcd_cmd(DOGM_CLEAR);
lcd_cmd(DOGM_ENTRY_MODE);
/* sample data */
lcd_data('C');
lcd_data('i');
lcd_data('r');
lcd_data('c');
lcd_data('l');
lcd_data('e');
lcd_data('C');
lcd_data('W');
lcd_data(' ');
lcd_data('9');
lcd_data('9');
lcd_data(' ');
lcd_data('1');
lcd_data('0');
lcd_data('.');
lcd_data('3');
lcd_data('1');
lcd_data('2');
lcd_data('.');
lcd_data('6');
lcd_data(' ');
lcd_data('M');
lcd_data(' ');
lcd_data('1');
lcd_data('2');
lcd_data('+');
lcd_data('3');
lcd_data(' ');
lcd_data('1');
lcd_data('4');
lcd_data('9');
lcd_data('3');
lcd_data('o');
lcd_data('k');
lcd_data(' ');
lcd_data('3');
lcd_data(' ');
lcd_data('0');
lcd_data('2');
lcd_data('1');
lcd_data(':');
lcd_data('3');
lcd_data('4');
lcd_data(' ');
lcd_data('1');
lcd_data('5');
lcd_data('0');
lcd_data('0');
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef LCD_DOGM_H
#define LCD_DOGM_H
#include <stdbool.h>
#include "std.h"
#include "spi_hw.h"
#include "led.h"
/* EA DOGM163, 3 line LCD at 3.3V */
#define DOGM_FUN_SET_1 0x39
#define DOGM_BIAS_SET 0x15
#define DOGM_PWR_CTRL 0x55
#define DOGM_FOLLOWER 0x6E
#define DOGM_CONTRAST 0x70
#define DOGM_FUN_SET_2 0x38
#define DOGM_DISP_ON 0x0C
#define DOGM_CLEAR 0x01
#define DOGM_ENTRY_MODE 0x06
extern void lcd_cmd(uint8_t command);
extern void lcd_data(uint8_t data);
extern void lcd_dogm_init( void );
#endif /* LCD_DOGM_H */