OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 196 to Rev 197
    Reverse comparison

Rev 196 → Rev 197

/aemb/trunk/sw/vpio/vpioGpio.h
27,16 → 27,20
#ifndef VPIO_GPIO_H
#define VPIO_GPIO_H
 
typedef char gpioData;
 
/*!
GPIO Directions.
*/
 
enum vpioGpioTrisType
enum gpioTrisType
{
GPIO_INPUT = 0, ///< Define GPIO pin as an input
GPIO_OUTPUT = 1 ///< Define GPIO pin as an output
};
 
typedef enum gpioTrisType gpioTrisType;
 
/*!
GPIO Register Map.
This structure contains the register file of a general-purpose
43,22 → 47,38
I/O. Care should be taken when using it due to endian issues.
*/
 
struct vpioGpioRegs
struct gpioRegs
{
volatile int regCtrl; ///< GPIO direction register.
//unsigned int /* unused */ :24;
volatile int regLine; ///< GPIO line data register.
//unsigned int /* unused */ :24;
volatile gpioData regCtrl; ///< GPIO direction register.
unsigned int /* unused */ :24;
volatile gpioData regLine; ///< GPIO line data register.
unsigned int /* unused */ :24;
};
 
typedef struct vpioGpioRegs vpioGpioRegs;
typedef struct gpioRegs gpioRegs;
 
// ==== GPIO INTERFACE ====
 
gpioData gpioGetBit(gpioRegs* port, gpioData bit);
void gpioSetBit(gpioRegs* port, gpioData bit);
void gpioTogBit(gpioRegs* port, gpioData bit);
void gpioClrBit(gpioRegs* port, gpioData bit);
 
//void gpioPutTris(gpioRegs* port, gpioData mask);
void gpioSetTris(gpioRegs* port, gpioData mask);
void gpioPutData(gpioRegs* port, gpioData data);
//gpioData gpioGetTris(gpioRegs* port);
gpioData gpioGetData(gpioRegs* port);
 
void gpioInit(gpioRegs* port);
 
 
/*!
Get a port bit.
This function reads the value of a specific bit on a GPIO port. It
reads the entire port line and masks out the specific bit. The
result should be interpreted as zero for 0 and non-zero for 1.
result should be gpioDataerpreted as zero for 0 and non-zero for 1.
@param port Memory-mapped I/O port.
@param bit Get port bit value.
66,7 → 86,7
*/
 
inline
int vpioGpioGetBit(vpioGpioRegs* port, int bit)
gpioData gpioGetBit(gpioRegs* port, gpioData bit)
{
return port->regLine & (1 << bit);
}
83,7 → 103,7
*/
 
inline
void vpioGpioSetBit(vpioGpioRegs* port, int bit)
void gpioSetBit(gpioRegs* port, gpioData bit)
{
port->regLine |= (1 << bit);
}
100,7 → 120,7
*/
 
inline
void vpioGpioTogBit(vpioGpioRegs* port, int bit)
void gpioTogBit(gpioRegs* port, gpioData bit)
{
port->regLine ^= (1 << bit);
}
117,7 → 137,7
*/
 
inline
void vpioGpioClrBit(vpioGpioRegs* port, int bit)
void gpioClrBit(gpioRegs* port, gpioData bit)
{
port->regLine &= ~(1 << bit);
}
129,18 → 149,38
direction of specific bits of the port. It writes the entire port
mask to the port control register.
 
@see vpioGpioTrisType
@see gpioTrisType
@param port Memory-mapped I/O port.
@param mask The entire port config mask.
*/
 
inline
void vpioGpioCfgPort(vpioGpioRegs* port, int mask)
void gpioSetTris(gpioRegs* port, gpioData mask)
{
port->regCtrl = mask;
}
 
 
/*!
Configure the entire port.
 
This function configures the entire port, which controls the
direction of specific bits of the port. It writes the entire port
mask to the port control register.
 
@see gpioTrisType
@param port Memory-mapped I/O port.
@param mask The entire port config mask.
*/
 
inline
gpioData gpioGetTris(gpioRegs* port)
{
//port->regCtrl = mask;
return port->regCtrl;
}
 
/*!
Put data on the port.
 
This function writes onto the entire data line of the GPIO port. It
151,7 → 191,7
*/
 
inline
void vpioGpioPutPort(vpioGpioRegs* port, int data)
void gpioPutData(gpioRegs* port, gpioData data)
{
port->regLine = data;
}
168,27 → 208,12
*/
 
inline
int vpioGpioGetPort(vpioGpioRegs* port)
gpioData gpioGetData(gpioRegs* port)
{
return port->regLine;
}
 
/*!
Clear the entire port.
 
This function clears the data pins of the entire GPIO port to 0. It
writes the value directly to the port register.
 
@param port Memory-mapped I/O port.
*/
 
inline
void vpioGpioClrPort(vpioGpioRegs* port)
{
vpioGpioPutPort(port, 0);
}
 
/*!
Initialise the GPIO port.
 
This function configures the entire GPIO port as inputs and clears
199,10 → 224,10
*/
 
inline
void vpioGpioIniPort(vpioGpioRegs* port)
void gpioInit(gpioRegs* port)
{
vpioGpioCfgPort(port, 0);
vpioGpioClrPort(port);
gpioSetTris(port, 0);
gpioPutData(port, 0);
}
 
#endif
/aemb/trunk/sw/vpio/vpioLcd.h
0,0 → 1,349
/* $Id: memtest.hh,v 1.8 2008-06-24 10:03:41 sybreon Exp $
**
** VIRTUAL PERIPHERAL I/O LIBRARY
** Copyright (C) 2009 Shawn Tan <shawn.tan@aeste.net>
**
** This file is part of AEMB.
**
** AEMB 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 3 of the License, or
** (at your option) any later version.
**
** AEMB 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 AEMB. If not, see <http://www.gnu.org/licenses/>.
*/
 
/*!
Character LCD Interface Library
@file
 
Interface library for standard HH44780/SED1278 character LCD
drivers. This library assumes a 4-bit hardware interface mode to
reduce the lines and GPIO width.
 
Routines modified from AVRLib by Pascal Stang.
*/
 
#include "vpioGpio.h"
 
#ifndef VPIO_LCD_H
#define VPIO_LCD_H
 
#define LCD_NIB 1 // nibble mode
#define WAIT_STATE 1
 
// GPIO control lines - DO NOT MODIFY
#define LCD_D7 7 // D7 - P14
#define LCD_D6 6 // D6 - P13
#define LCD_D5 5 // D5 - P12
#define LCD_D4 4 // D4 - P11
#define LCD_EN 3 // EN - P6
#define LCD_RW 2 // RW - P5
#define LCD_RS 1 // RS - P4
#define LCD_HB 0 // HB - NC
 
// HD44780 LCD controller command set (do not modify these)
// writing:
#define LCD_CLR 0 // DB0: clear display
#define LCD_HOME 1 // DB1: return to home position
#define LCD_ENTRY_MODE 2 // DB2: set entry mode
#define LCD_ENTRY_INC 1 // DB1: increment
#define LCD_ENTRY_SHIFT 0 // DB2: shift
#define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on
#define LCD_ON_DISPLAY 2 // DB2: turn display on
#define LCD_ON_CURSOR 1 // DB1: turn cursor on
#define LCD_ON_BLINK 0 // DB0: blinking cursor
#define LCD_MOVE 4 // DB4: move cursor/display
#define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor)
#define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left)
#define LCD_FUNCTION 5 // DB5: function set
#define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode)
#define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line)
#define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font)
#define LCD_CGRAM 6 // DB6: set CG RAM address
#define LCD_DDRAM 7 // DB7: set DD RAM address
// reading:
#define LCD_BUSY 7 // DB7: LCD is busy
 
// Default LCD setup
// this default setup is loaded on LCD initialization
#define LCD_FDEF_1 (0<<LCD_FUNCTION_8BIT)
#define LCD_FDEF_2 (1<<LCD_FUNCTION_2LINES)
#define LCD_FUNCTION_DEFAULT ((1<<LCD_FUNCTION) | LCD_FDEF_1 | LCD_FDEF_2)
#define LCD_MODE_DEFAULT ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC))
 
#define LCD_OUTPUT 0xFF
#define LCD_INPUT 0x0F
 
typedef struct gpioRegs lcdRegs;
 
// Low-level I/O functions
void lcdReset(lcdRegs* lcd);
void lcdWaitBusy(lcdRegs* lcd);
void lcdPutControl(lcdRegs* lcd, char ctrl);
char lcdGetControl(lcdRegs* lcd);
void lcdPutData(lcdRegs* lcd, char data);
char lcdGetData(lcdRegs* lcd);
void lcdDelay(int ms);
//void lcdSetTris(lcdRegs* lcd, gpioTrisType dir);
 
// High-level application functions
void lcdInit(lcdRegs* lcd);
void lcdHome(lcdRegs* lcd);
void lcdClear(lcdRegs* lcd);
 
 
/*!
Reset the LCD hardware.
 
@param lcd LCD GPIO port.
*/
 
void lcdReset(lcdRegs* lcd)
{
// set GPIO to output
gpioSetTris(lcd, LCD_OUTPUT);
 
// clear lines
/*
gpioClrBit(lcd, LCD_RS);
gpioClrBit(lcd, LCD_RW);
gpioClrBit(lcd, LCD_EN);
*/
gpioPutData(lcd, 0x00);
 
// set lines
/*
gpioSetBit(lcd, LCD_RS);
gpioSetBit(lcd, LCD_RW);
gpioSetBit(lcd, LCD_EN);
*/
gpioPutData(lcd, 0xFF);
 
// set GPIO to input
gpioSetTris(lcd, LCD_INPUT);
}
 
/*!
Blocking wait for LCD busy signal.
 
This function blocks the LCD port while the busy signal is asserted
by the LCD.
 
@param lcd LCD GPIO port.
*/
void lcdWaitBusy(lcdRegs* lcd)
{
int i;
gpioSetTris(lcd, LCD_INPUT); // set INPUT
//gpioClrBit(lcd, LCD_RS); // select CONTROL
//gpioSetBit(lcd, LCD_RW); // set to READ
//gpioSetBit(lcd, LCD_EN);
gpioPutData(lcd, (1<<LCD_RW) | (1<<LCD_EN)); // EN|RD|CT
lcdDelay(WAIT_STATE);
while (gpioGetBit(lcd, LCD_BUSY))
{
for (i = 2; i>0; --i)
{
/*
gpioClrBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
*/
gpioPutData(lcd, (1<<LCD_RW) );
lcdDelay(WAIT_STATE);
gpioPutData(lcd, (1<<LCD_RW) | (1<<LCD_EN) );
lcdDelay(WAIT_STATE);
}
}
 
gpioPutData(lcd, (1<<LCD_RW) );
//gpioClrBit(lcd, LCD_EN);
//gpioTogBit(lcd, LCD_HB);
}
 
/*!
Write a control byte to the LCD.
 
This function writes a byte to the LCD control register.
@param lcd LCD GPIO port.
@param ctrl Control byte to write
*/
void lcdPutControl(lcdRegs* lcd, char ctrl)
{
lcdWaitBusy(lcd); // wait until free
//gpioClrBit(lcd, LCD_RS); // select CONTROL
//gpioClrBit(lcd, LCD_RW); // set to WRITE
gpioPutData(lcd, (1<<LCD_HB));
gpioSetTris(lcd, LCD_OUTPUT); // Set OUTPUT
 
gpioPutData(lcd, (gpioGetData(lcd) & 0x0F) | (ctrl & 0xF0) );
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioPutData(lcd, (gpioGetData(lcd) & 0x0F) | (ctrl << 4) );
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
gpioSetTris(lcd, LCD_INPUT); // set INPUT
}
 
/*!
Read a control byte from the LCD.
 
This function reads a control byte from the LCD control register.
@param lcd LCD GPIO port.
@return control register value.
*/
 
char lcdGetControl(lcdRegs* lcd)
{
char b;
lcdWaitBusy(lcd); // wait until free
gpioSetTris(lcd, LCD_INPUT); // Set INPUT
//gpioClrBit(lcd, LCD_RS); // select CONTROL
//gpioSetBit(lcd, LCD_RW); // set to READ
//gpioSetBit(lcd, LCD_EN);
gpioPutData(lcd, (1<<LCD_RW) | (1<<LCD_EN) );
lcdDelay(WAIT_STATE);
 
b = gpioGetData(lcd) & 0xF0; // read upper nib
gpioClrBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
b |= (gpioGetData(lcd) >> 4); // read lower nib
gpioSetTris(lcd, LCD_INPUT); // set INPUT
return b;
}
 
/*!
Write a data byte to the LCD.
 
This function writes a byte to the LCD data register.
@param lcd LCD GPIO port.
@param ctrl Control byte to write
*/
void lcdPutData(lcdRegs* lcd, char data)
{
lcdWaitBusy(lcd); // wait until free
//gpioSetBit(lcd, LCD_RS); // select DATA
//gpioClrBit(lcd, LCD_RW); // set to WRITE
gpioPutData(lcd, (1<<LCD_RS) );
gpioSetTris(lcd, LCD_OUTPUT); // Set OUTPUT
 
gpioPutData(lcd, (gpioGetData(lcd) & 0x0F) | (data & 0xF0) );
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioPutData(lcd, (gpioGetData(lcd) & 0x0F) | (data << 4) );
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
//gpioPutData(lcd, (1<<LCD_RS) );
gpioSetTris(lcd, LCD_INPUT); // set INPUT
}
 
/*!
Read a data byte from the LCD.
 
This function reads a control byte from the LCD control register.
@param lcd LCD GPIO port.
@return data register value.
*/
 
char lcdGetData(lcdRegs* lcd)
{
char b;
lcdWaitBusy(lcd); // wait until free
gpioSetTris(lcd, LCD_INPUT); // Set INPUT
gpioSetBit(lcd, LCD_RS); // select DATA
gpioSetBit(lcd, LCD_RW); // set to READ
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
b = gpioGetData(lcd) & 0xF0; // read upper nib
gpioClrBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioSetBit(lcd, LCD_EN);
lcdDelay(WAIT_STATE);
gpioClrBit(lcd, LCD_EN);
b |= (gpioGetData(lcd) >> 4); // read lower nib
gpioSetTris(lcd, LCD_INPUT); // set INPUT
return b;
}
 
/*!
Initialisation Routine.
 
This function brings the LCD through the standard initialisation
process. It sets the LCD mode to default entry modes, clears the
screen and cursors to home.
 
@param lcd LCD GPIO port.
*/
 
void lcdInit(lcdRegs* lcd)
{
lcdReset(lcd); // reset HW
lcdPutControl(lcd, LCD_FUNCTION_DEFAULT);
lcdPutControl(lcd, 1 << LCD_CLR);
lcdDelay(0x00008000); // delay 30ms+
 
lcdPutControl(lcd, 1 << LCD_ENTRY_MODE | 1 << LCD_ENTRY_INC);
lcdPutControl(lcd, 1 << LCD_ON_CTRL | 1 << LCD_ON_DISPLAY);
 
lcdPutControl(lcd, 1 << LCD_HOME);
lcdPutControl(lcd, 1 << LCD_DDRAM | 0x00);
}
 
/*!
Arbitrary delay routine.
 
This function does a NOP loop for an arbitrary number of cycles. The
cycles are not calibrated to any clock but is assumed to run on a
nominal 100MHz clock.
@param us Assume number of micro-seconds (us).
*/
 
inline
void lcdDelay(int us)
{
int i;
//for (i = 0; i < (ms << 3); ++i) { asm volatile ("nop"); } // do NOP
for (i = us << 4; i > 0; --i) { asm volatile ("nop"); } // do NOP
}
 
/*!
Returns the LCD cursor to home.
 
@param lcd LCD GPIO port.
*/
void lcdHome(lcdRegs* lcd)
{
lcdPutControl(lcd, 1<<LCD_HOME);
}
 
/*!
Clear the LCD screen.
 
@param lcd LCD GPIO port.
*/
void lcdClear(lcdRegs* lcd)
{
lcdPutControl(lcd, 1<<LCD_CLR);
}
 
#endif
/aemb/trunk/sw/vpio/vpioGpio.hh
37,6 → 37,8
}
#endif
 
namespace vpio {
 
/*!
General-Purpose I/O Class.
 
43,30 → 45,35
This is a C++ wrapper class around the low-level C code.
*/
 
class vpioGpioClass : public vpioGpioRegs
class gpioClass : public gpioRegs
{
private:
//vpioGpioClass(const vpioGpioClass&);
//vpioGpioClass();
vpioGpioClass& operator=(const vpioGpioClass&);
//gpioClass(const gpioClass&);
//gpioClass();
gpioClass& operator=(const gpioClass&);
public:
 
//void IniPort(int base_addr) { this = (vpioGpioRegs*)base_addr; }
//void IniPort(int base_addr) { this = (gpioRegs*)base_addr; }
void SetBit(int bit) { vpioGpioSetBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioSetBit
void ClrBit(int bit) { vpioGpioClrBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioClrBit
void TogBit(int bit) { vpioGpioTogBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioTogBit
int GetBit(int bit) { return vpioGpioGetBit( (vpioGpioRegs*)this, bit); } ///< @see vpioGpioGetBit
void SetBit(gpioData bit) { gpioSetBit( (gpioRegs*)this, bit); } ///< @see gpioSetBit
void ClrBit(gpioData bit) { gpioClrBit( (gpioRegs*)this, bit); } ///< @see gpioClrBit
void TogBit(gpioData bit) { gpioTogBit( (gpioRegs*)this, bit); } ///< @see gpioTogBit
gpioData GetBit(gpioData bit) { return gpioGetBit( (gpioRegs*)this, bit); } ///< @see gpioGetBit
// Port Manipulation
void CfgPort(int mask) { vpioGpioCfgPort( (vpioGpioRegs*)this, mask); } ///< @see vpioGpioCfgPort
void PutPort(int data) { vpioGpioPutPort( (vpioGpioRegs*)this, data); } ///< @see vpioGpioPutPort
void ClrPort() { vpioGpioClrPort( (vpioGpioRegs*)this ); } ///< @see vpioGpioClrPort
int GetPort() { return vpioGpioGetPort( (vpioGpioRegs*)this ); } ///< @see vpioGpioGetPort
//void PutTris(gpioData mask) { gpioPutTris( (gpioRegs*)this, mask); } ///< @see gpioPutTris
void SetTris(gpioData mask) { gpioSetTris( (gpioRegs*)this, mask); } ///< @see gpioSetTris
void PutData(gpioData data) { gpioPutData( (gpioRegs*)this, data); } ///< @see gpioPutData
//void ClrPort() { gpioClrPort( (gpioRegs*)this ); } ///< @see gpioClrPort
//gpioData GetTris() { return gpioGetTris( (gpioRegs*)this ); } ///< @see gpioGetTris
gpioData GetData() { return gpioGetData( (gpioRegs*)this ); } ///< @see gpioGetData
void Init() { gpioInit( (gpioRegs*)this ); } ///< @see gpioInit
};
 
}
 
#endif
/aemb/trunk/sw/vpio/vpioLcd.hh
0,0 → 1,75
/* $Id: memtest.hh,v 1.8 2008-06-24 10:03:41 sybreon Exp $
**
** VIRTUAL PERIPHERAL I/O LIBRARY
** Copyright (C) 2009 Shawn Tan <shawn.tan@aeste.net>
**
** This file is part of AEMB.
**
** AEMB 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 3 of the License, or
** (at your option) any later version.
**
** AEMB 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 AEMB. If not, see <http://www.gnu.org/licenses/>.
*/
 
/*!
Character LCD C++ Interface.
@file vpioLcd.hh
 
This file provides a C++ wrapper class to the low-level C interface.
*/
 
#ifndef VPIO_LCD_HH
#define VPIO_LCD_HH
 
#ifdef __cplusplus
extern "C" {
#endif
#include "vpioLcd.h"
#ifdef __cplusplus
}
#endif
 
namespace vpio {
 
/*!
General-Purpose I/O Class.
 
This is a C++ wrapper class around the low-level C code.
*/
 
class lcdClass : public lcdRegs
{
private:
 
lcdClass& operator=(const lcdClass&);
public:
 
// Low-level I/O functions
void Reset() { lcdReset((lcdRegs*)this); } ///< @see lcdReset
void WaitBusy() { lcdWaitBusy((lcdRegs*)this); } ///< @see lcdWaitBusy
void PutControl(char ctrl) { lcdPutControl((lcdRegs*)this, ctrl); } ///< @see lcdPutControl
char GetControl() { return lcdGetControl((lcdRegs*)this); } ///< @see lcdGetControl
void PutData(char data) { lcdPutData((lcdRegs*)this,data); } ///< @see lcdPutData
char GetData() { return lcdGetData((lcdRegs*)this); } ///< @see lcdGetData
void Delay(int ms) { lcdDelay(ms); } ///< @see lcdDelay
// High-level application functions
void Init() { lcdInit((lcdRegs*)this); } ///< @see lcdInit
void Home() { lcdHome((lcdRegs*)this); } ///< @see lcdHome
void Clear() { lcdClear((lcdRegs*)this); } ///< @see lcdClear
 
};
 
}
 
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.