pca9685reg.h revision 1.1 1 1.1 thorpej /* $NetBSD: pca9685reg.h,v 1.1 2019/07/24 05:25:32 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2018 Jason R. Thorpe
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej #ifndef pca9685reg_h_included
30 1.1 thorpej #define pca9685reg_h_included
31 1.1 thorpej
32 1.1 thorpej /*
33 1.1 thorpej * Hardware definitions for the NXP PCA9685 16-channel, 12-bit PWM FM+
34 1.1 thorpej * I2C-bus LED controller.
35 1.1 thorpej */
36 1.1 thorpej
37 1.1 thorpej #define PCA9685_NCHANNELS 16
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * PCA9685 i2c addresses.
41 1.1 thorpej */
42 1.1 thorpej /* Default all-call address. */
43 1.1 thorpej #define PCA9685_I2CADDR_ALLCALL_DEFAULT 0x70
44 1.1 thorpej
45 1.1 thorpej /* Default sub-addresses. */
46 1.1 thorpej #define PCA9685_I2CADDR_SUBADR1_DEFAULT 0x71
47 1.1 thorpej #define PCA9685_I2CADDR_SUBADR2_DEFAULT 0x72
48 1.1 thorpej #define PCA9685_I2CADDR_SUBADR3_DEFAULT 0x74
49 1.1 thorpej
50 1.1 thorpej /*
51 1.1 thorpej * The PCA9685 has 6 address select pins, which must be
52 1.1 thorpej * pulled up or down to select the device's address. The
53 1.1 thorpej * selected slave address is:
54 1.1 thorpej *
55 1.1 thorpej * 1 A5 A4 A3 A2 A1 A0
56 1.1 thorpej *
57 1.1 thorpej * There are some addresses, however, that cannot be selected
58 1.1 thorpej * even if they fall into the selectable range:
59 1.1 thorpej *
60 1.1 thorpej * - Default all-call address (0x70)
61 1.1 thorpej * - 10-bit slave address prefix (0x78)
62 1.1 thorpej * - Reserved for future purposes address (0x7c)
63 1.1 thorpej *
64 1.1 thorpej * Use of sub-addresses to control groups of devices also limits
65 1.1 thorpej * the available individual slave addresses.
66 1.1 thorpej */
67 1.1 thorpej #define PCA9685_I2CADDR_MIN 0x40
68 1.1 thorpej #define PCA9685_I2CADDR_MAX 0x7f
69 1.1 thorpej
70 1.1 thorpej #define PCA9685_I2CADDR_BLACKLIST { 0x78, 0x7c }
71 1.1 thorpej
72 1.1 thorpej /*
73 1.1 thorpej * PCA9685 has an internal 25MHz oscillator. The maximum external
74 1.1 thorpej * reference clock frequency is 50MHz.
75 1.1 thorpej */
76 1.1 thorpej #define PCA9685_INTERNAL_FREQ 25000000
77 1.1 thorpej #define PCA9685_EXTERNAL_FREQ_MAX 50000000
78 1.1 thorpej
79 1.1 thorpej /*
80 1.1 thorpej * Data sheet sez:
81 1.1 thorpej *
82 1.1 thorpej * Maximum PWM frequency is 1526Hz -- prescale == 0x03.
83 1.1 thorpej * Minimum PWM frequency is 24Hz -- prescale == 0xff.
84 1.1 thorpej */
85 1.1 thorpej #define PCA9685_FREQ_MIN 24
86 1.1 thorpej #define PCA9685_FREQ_MAX 1526
87 1.1 thorpej
88 1.1 thorpej #define PCA9685_PRESCALE_MIN 0x03
89 1.1 thorpej #define PCA9685_PRESCALE_MAX 0xff
90 1.1 thorpej
91 1.1 thorpej /*
92 1.1 thorpej * The PCA9685 pulse counter has a 12-bit resolution (4096 ticks).
93 1.1 thorpej */
94 1.1 thorpej #define PCA9685_PWM_TICKS 4096
95 1.1 thorpej
96 1.1 thorpej /*
97 1.1 thorpej * PCA9685 register definitions.
98 1.1 thorpej */
99 1.1 thorpej
100 1.1 thorpej /* Mode register 1 */
101 1.1 thorpej #define PCA9685_MODE1 0x00
102 1.1 thorpej #define MODE1_ALLCALL 0x01 /* responds to LED All Call address */
103 1.1 thorpej #define MODE1_SUB3 0x02 /* responds to subaddress 3 */
104 1.1 thorpej #define MODE1_SUB2 0x04 /* responds to subaddress 2 */
105 1.1 thorpej #define MODE1_SUB1 0x08 /* responds to subaddress 1 */
106 1.1 thorpej #define MODE1_SLEEP 0x10 /* 1 = low power mode, oscillator off */
107 1.1 thorpej #define MODE1_AI 0x20 /* register auto-increment enabled */
108 1.1 thorpej #define MODE1_EXTCLK 0x40 /* external oscillatior enable */
109 1.1 thorpej #define MODE1_RESTART 0x80 /* restart enabled */
110 1.1 thorpej
111 1.1 thorpej /* Mode register 2 */
112 1.1 thorpej #define PCA9685_MODE2 0x01
113 1.1 thorpej #define MODE2_OUTNE_MASK 0x03 /* see data sheet */
114 1.1 thorpej #define MODE2_OUTDRV 0x04 /* 0 = open-drain, 1 = totem pole */
115 1.1 thorpej #define MODE2_OCH 0x08 /* outputs change: 0 = STOP, 1 = ACK */
116 1.1 thorpej #define MODE2_INVRT 0x10 /* Output logic state inverted */
117 1.1 thorpej
118 1.1 thorpej /* I2C subaddress 1 */
119 1.1 thorpej #define PCA9685_SUBADR1 0x02
120 1.1 thorpej
121 1.1 thorpej /* I2C subaddress 2 */
122 1.1 thorpej #define PCA9685_SUBADR2 0x03
123 1.1 thorpej
124 1.1 thorpej /* I2C subaddress 3 */
125 1.1 thorpej #define PCA9685_SUBADR3 0x04
126 1.1 thorpej
127 1.1 thorpej /* LED All Call address */
128 1.1 thorpej #define PCA9685_ALLCALLADR 0x05
129 1.1 thorpej
130 1.1 thorpej /* LEDx output and brightness control byte 0 */
131 1.1 thorpej #define PCA9685_LEDx_ON_L(x) (0x06 + ((x) * 4))
132 1.1 thorpej
133 1.1 thorpej /* LEDx output and brightness control byte 1 */
134 1.1 thorpej #define PCA9685_LEDx_ON_H(x) (0x07 + ((x) * 4))
135 1.1 thorpej
136 1.1 thorpej /* LEDx output and brightness control byte 2 */
137 1.1 thorpej #define PCA9685_LEDx_OFF_L(x) (0x08 + ((x) * 4))
138 1.1 thorpej
139 1.1 thorpej /* LEDx output and brightness control byte 3 */
140 1.1 thorpej #define PCA9685_LEDx_OFF_H(x) (0x09 + ((x) * 4))
141 1.1 thorpej
142 1.1 thorpej /* Load all LEDx_ON registers byte 0 */
143 1.1 thorpej #define PCA9685_ALL_LED_ON_L 0xfa
144 1.1 thorpej
145 1.1 thorpej /* Load all LEDx_ON registers byte 1 */
146 1.1 thorpej #define PCA9685_ALL_LED_ON_H 0xfb
147 1.1 thorpej
148 1.1 thorpej /* Load all LEDx_OFF registers byte 0 */
149 1.1 thorpej #define PCA9685_ALL_LED_OFF_L 0xfc
150 1.1 thorpej
151 1.1 thorpej /* Load all LEDx_OFF registers byte 1 */
152 1.1 thorpej #define PCA9685_ALL_LED_OFF_H 0xfd
153 1.1 thorpej
154 1.1 thorpej /* Prescaler for PWM output frequency */
155 1.1 thorpej #define PCA9685_PRE_SCALE 0xfe
156 1.1 thorpej
157 1.1 thorpej /* Test mode */
158 1.1 thorpej #define PCA9685_TEST_MODE 0xff
159 1.1 thorpej
160 1.1 thorpej #endif /* pca9685reg_h_included */
161