I2C and LCD bug fixes
[hackover2013-badge-firmware.git] / core / i2c / i2c.h
1 /*****************************************************************************
2 * i2c.h: Header file for NXP LPC11xx Family Microprocessors
3 *
4 * Copyright(C) 2006, NXP Semiconductor
5 * Parts of this code are (C) 2010, MyVoice CAD/CAM Services
6 * All rights reserved.
7 *
8 * History
9 * 2006.07.19 ver 1.00 Preliminary version, first Release
10 * 2010.07.19 ver 1.10 Rob Jansen - MyVoice CAD/CAM Services
11 * Updated to reflect new code
12 *
13 ******************************************************************************/
14 #ifndef __I2C_H
15 #define __I2C_H
16
17 #include "projectconfig.h"
18
19 /*
20 * These are states returned by the I2CEngine:
21 *
22 * IDLE - is never returned but only used internally
23 * PENDING - is never returned but only used internally in the I2C functions
24 * ACK - The transaction finished and the slave returned ACK (on all bytes)
25 * NACK - The transaction is aborted since the slave returned a NACK
26 * SLA_NACK - The transaction is aborted since the slave returned a NACK on the SLA
27 * this can be intentional (e.g. an 24LC08 EEPROM states it is busy)
28 * or the slave is not available/accessible at all.
29 * ARB_LOSS - Arbitration loss during any part of the transaction.
30 * This could only happen in a multi master system or could also
31 * identify a hardware problem in the system.
32 */
33 #define I2CSTATE_IDLE 0x000
34 #define I2CSTATE_PENDING 0x001
35 #define I2CSTATE_ACK 0x101
36 #define I2CSTATE_NACK 0x102
37 #define I2CSTATE_SLA_NACK 0x103
38 #define I2CSTATE_ARB_LOSS 0x104
39
40 #define FAST_MODE_PLUS 0
41
42 #define I2C_BUFSIZE 64
43 #define MAX_TIMEOUT 0x00FFFFFF
44
45 #define I2CMASTER 0x01
46 #define I2CSLAVE 0x02
47
48 #define SLAVE_ADDR 0xA0
49 #define READ_WRITE 0x01
50
51 #define RD_BIT 0x01
52
53 #define I2C_GENERALCALL 0x00 /* General Call Address (to 'ping' I2C bus for devices) */
54
55 #define I2CONSET_I2EN 0x00000040 /* I2C Control Set Register */
56 #define I2CONSET_AA 0x00000004
57 #define I2CONSET_SI 0x00000008
58 #define I2CONSET_STO 0x00000010
59 #define I2CONSET_STA 0x00000020
60
61 #define I2CONCLR_AAC 0x00000004 /* I2C Control clear Register */
62 #define I2CONCLR_SIC 0x00000008
63 #define I2CONCLR_STAC 0x00000020
64 #define I2CONCLR_I2ENC 0x00000040
65
66 #define I2DAT_I2C 0x00000000 /* I2C Data Reg */
67 #define I2ADR_I2C 0x00000000 /* I2C Slave Address Reg */
68
69 /* SCLH and SCLL = I2C PCLK High/Low cycles for I2C clock and
70 determine the data rate/duty cycle for I2C:
71
72 I2CBitFrequency = I2CPCLK / (I2CSCLH + I2CSCLL)
73
74 Standard Mode (100KHz) = CFG_CPU_CCLK / 200000
75 Fast Mode (400KHz) = CFG_CPU_CCLK / 800000
76 Fast- Mode Plus (1MHz) = CFG_CPU_CCLK / 2000000 */
77
78 #define I2SCLH_SCLH CFG_CPU_CCLK / 800000 /* Standard Mode I2C SCL Duty Cycle High (400KHz) */
79 #define I2SCLL_SCLL CFG_CPU_CCLK / 800000 /* Fast Mode I2C SCL Duty Cycle Low (400KHz) */
80 #define I2SCLH_HS_SCLH CFG_CPU_CCLK / 2000000 /* Fast Plus I2C SCL Duty Cycle High Reg */
81 #define I2SCLL_HS_SCLL CFG_CPU_CCLK / 2000000 /* Fast Plus I2C SCL Duty Cycle Low Reg */
82
83 extern volatile uint8_t I2CMasterBuffer[I2C_BUFSIZE];
84 extern volatile uint8_t I2CSlaveBuffer[I2C_BUFSIZE];
85 extern volatile uint32_t I2CReadLength, I2CWriteLength;
86
87 extern void I2C_IRQHandler( void );
88 extern uint32_t i2cInit( uint32_t I2cMode );
89 extern uint32_t i2cEngine( void );
90 uint32_t i2cSendGeneralCall( void );
91
92 #endif /* end __I2C_H */
93 /****************************************************************************
94 ** End Of File
95 *****************************************************************************/
This page took 0.048484 seconds and 5 git commands to generate.