Aruna
PCA9685.h
Go to the documentation of this file.
1 //
2 // Created by noeel on 18-10-20.
3 //
4 
5 #ifndef ARUNA_PCA9685_H
6 #define ARUNA_PCA9685_H
7 
8 #include "aruna/driver/Pwm.h"
10 #include "aruna/log.h"
11 #include "pthread.h"
12 
13 namespace aruna {
14  namespace driver {
15  class PCA9685 : public Pwm {
16  private:
17 
23  MODE1 = 0x0,
24  MODE2 = 0x1,
25  SUBADR1 = 0x2,
26  SUBADR2 = 0x3,
27  SUBADR3 = 0x4,
28  ALLCALLADR = 0x5,
29  LED0_ON_L = 0x6,
30 
31  ALL_LED_ON_L = 0xFA,
32  PRE_SCALE = 0xFE,
33  TESTMODE = 0xFF,
34 
35  };
36 
37 // Mode 1
38  enum class RESTART {
39  DEFAULT = 0x0,
40  DISABLED = 0x0,
41  ENABLED = 0x80,
42  };
43 
44  enum class EXTCLK {
45  DEFAULT = 0x0,
46  USE_INTERNAL_CLOCK = 0x0,
47  USE_EXTCLK_PIN_CLOCK = 0x40,
48  };
49 
50  enum class AI {
51  DEFAULT = 0x0,
52  AUTO_INCREMENT_DISABLED = 0x0,
53  AUTO_INCREMENT_ENABLED = 0x20,
54  };
55 
56  enum class SLEEP {
57  DEFAULT = 0x10,
58  NORMAL_MODE = 0x0,
59  LOW_POWER = 0x10,
60  };
61 
62  enum class SUB1 {
63  DEFAULT = 0x0,
64  NOT_RESPOND_TO_SUBADDRESS1 = 0x0,
65  RESPOND_TO_SUBADDRESS1 = 0x8,
66  };
67 
68  enum class SUB2 {
69  DEFAULT = 0x0,
70  NOT_RESPOND_TO_SUBADDRESS2 = 0x0,
71  RESPOND_TO_SUBADDRESS2 = 0x4,
72  };
73 
74  enum class SUB3 {
75  DEFAULT = 0x0,
76  NOT_RESPOND_TO_SUBADDRESS3 = 0x0,
77  RESPOND_TO_SUBADDRESS3 = 0x2,
78  };
79 
80  enum class ALLCALL {
81  DEFAULT = 0x1,
82  NOT_RESPOND_TO_LED_ALL = 0x0,
83  RESPOND_TO_LED_ALL = 0x1,
84  };
85 
86 // Mode 2
87  enum class INVRT {
88  DEFAULT = 0x0,
89  OUTPUT_LOGIC_NOT_INVERTED = 0x0,
90  OUTPUT_LOGIC_INVERTED = 0x10,
91  };
92 
93  enum class OCH {
94  DEFAULT = 0x0,
95  OUTPUT_CHANGE_ON_STOP_COMMAND = 0x0,
96  OUTPUT_CHANGE_ON_ACK = 0x8,
97  };
98 
99  enum class OUTDRV {
100  DEFAULT = 0x4,
101  OPEN_DRAIN = 0x0,
102  TOTEM_POLE = 0x4,
103  };
104 
105  enum class OUTNE {
106  DEFAULT = 0x0,
107  LEDn_0 = 0x0,
108  LEDn_1_OUTDRV_1 = 0b01,
109  LEDn_HIGH_IMPEDANCE = 0b10,
110  };
111 
112  uint8_t const static default_i2c_address = 0b1000000;
113  const uint8_t led, i2c_address;
115 
116  err_t _set_frequency(uint32_t frequency_hz) override;
117 
118  err_t _set_duty(uint16_t duty) override;
119  public:
126  PCA9685(uint8_t led, I2C_master *i2c_bus, uint8_t i2c_address = default_i2c_address);
127 // TODO supply a default i2c_bus per port in aruna_port.h or something
128 
129  ~PCA9685();
130 
131 
132 // TODO without override does this function get called?
133  uint32_t get_frequency();
134 
135 
142  err_t set_duty(uint16_t on, uint16_t off);
143 
144 // TODO without override does this function get called?
145  uint16_t get_duty();
146 
153  err_t get_duty(uint16_t &on, uint16_t &off);
154 
165 
166 // TODO support for SUBADRx
167 // TODO support for ALLCALLADR
168 // TODO support ALL_LED write
169 // TODO support write/read mode1/2 directly
170  };
171  }
172 }
173 
174 
175 #endif //ARUNA_PCA9685_H
Definition: comm.cpp:14
err_t _set_duty(uint16_t duty) override
Definition: PCA9685.cpp:71
uint16_t get_duty()
Definition: PCA9685.cpp:89
err_t is_connected()
Is the PCA9685 connected to the I²C bus.
Definition: PCA9685.cpp:114
PCA9685(uint8_t led, I2C_master *i2c_bus, uint8_t i2c_address=default_i2c_address)
PCA9685 pwm object for every LED.
Definition: PCA9685.cpp:13
uint8_t static const default_i2c_address
Definition: PCA9685.h:112
uint16_t duty
Definition: Pwm.h:16
uint32_t get_frequency()
Definition: PCA9685.cpp:60
static aruna::log::channel_t log
Definition: PCA9685.h:18
err_t _set_frequency(uint32_t frequency_hz) override
Definition: PCA9685.cpp:34
const uint8_t led
Definition: PCA9685.h:113
I2C_master * i2c_bus
Definition: PCA9685.h:114
Link * driver
stores the driver.
Definition: comm.cpp:45
const uint8_t i2c_address
Definition: PCA9685.h:113
err_t set_duty(uint16_t on, uint16_t off)
Set the on and off timing of the PCA9685 led.
Definition: PCA9685.cpp:79
register_address_pointer
Pointer to the registers.
Definition: PCA9685.h:22
uint32_t frequency_hz
Definition: Pwm.h:15