-
Notifications
You must be signed in to change notification settings - Fork 0
/
pca9532.c
116 lines (92 loc) · 3.15 KB
/
pca9532.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/******************************************************************************
*
* Copyright:
* (C) 2006 Embedded Artists AB
*
* File:
* pca9532.c
*
* Description:
* Implements hardware specific routines
*
*****************************************************************************/
/******************************************************************************
* Includes
*****************************************************************************/
#include "../pre_emptive_os/api/osapi.h"
#include "../pre_emptive_os/api/general.h"
#include <lpc2xxx.h>
#include <printf_P.h>
#include "util/i2c.h"
#include "util/eeprom/eeprom.h"
#include "pca9532.h"
/******************************************************************************
* Typedefs and defines
*****************************************************************************/
/*****************************************************************************
* Global variables
****************************************************************************/
/*****************************************************************************
* Local variables
****************************************************************************/
/*****************************************************************************
* Local prototypes
****************************************************************************/
/*****************************************************************************
*
* Description:
* Initialize the io-pins and find out if HW is ver 1.0 or ver 1.1
*
****************************************************************************/
tBool
pca9532Init(void) {
tU8 initCommand[] = {0x12, 0x97, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00};
// 04 = LCD_RST# low
// 10 = BT_RST# low
//initialize PCA9532
if (I2C_CODE_OK == pca9532(initCommand, sizeof(initCommand), NULL, 0))
return TRUE;
else
return FALSE;
}
/*****************************************************************************
*
* Description:
*
****************************************************************************/
void
setPca9532Pin(tU8 pinNum, tU8 value) {
tU8 command[] = {0x00, 0x00};
tU8 regValue;
tU8 mask;
if (pinNum < 4)
command[0] = 0x06;
else if (pinNum < 8)
command[0] = 0x07;
else if (pinNum < 12)
command[0] = 0x08;
else
command[0] = 0x09;
pca9532(command, 1, ®Value, 1);
mask = (3 << 2 * (pinNum % 4));
regValue &= ~mask;
if (value == 0)
command[1] = 0x01;
else
command[1] = 0x00;
command[1] <<= 2 * (pinNum % 4);
command[1] |= regValue;
pca9532(command, sizeof(command), NULL, 0);
}
/*****************************************************************************
*
* Description:
*
****************************************************************************/
tU16
getPca9532Pin(void) {
tU8 command[] = {0x19};
tU8 regValue[3];
pca9532(command, 1, regValue, 3);
return (tU16) regValue[1] | ((tU16) regValue[2] << 8);
}