|
5 | 5 | /* */
|
6 | 6 | /* OpenPOWER HostBoot Project */
|
7 | 7 | /* */
|
8 |
| -/* Contributors Listed Below - COPYRIGHT 2014 */ |
| 8 | +/* Contributors Listed Below - COPYRIGHT 2014,2019 */ |
9 | 9 | /* [+] Google Inc. */
|
10 | 10 | /* [+] International Business Machines Corp. */
|
11 | 11 | /* */
|
|
26 | 26 | #ifndef __GPIOIF_H
|
27 | 27 | #define __GPIOIF_H
|
28 | 28 |
|
| 29 | +#include <errl/errlentry.H> |
| 30 | + |
29 | 31 | namespace GPIO
|
30 | 32 | {
|
31 | 33 | /**
|
32 | 34 | * @brief Devices to be accessed
|
33 | 35 | */
|
34 | 36 | enum gpioDevice_t
|
35 | 37 | {
|
36 |
| - PCA95X_GPIO = 0, |
| 38 | + // Corresponds to attribute ... |
| 39 | + PCA95X_GPIO = 0, // GPIO_INFO |
| 40 | + PCA9551_GPIO_PHYS_PRES = 1, // GPIO_INFO_PHYS_PRES |
37 | 41 | INVALID_GPIO,
|
38 | 42 | };
|
39 | 43 |
|
40 | 44 |
|
| 45 | +/* The following enums and interfaces are specific to PCA9551 GPIO Devices. |
| 46 | + * Documentation here: https://www.nxp.com/docs/en/data-sheet/PCA9551.pdf |
| 47 | + */ |
| 48 | + |
| 49 | +/** |
| 50 | + * @brief Specific to PCA9551: LED Bit Mask to match how their status is read |
| 51 | + * back from LED "INPUT" register on PCA9551 Devices |
| 52 | + */ |
| 53 | +enum PCA9551_LEDS_t : uint8_t |
| 54 | +{ |
| 55 | + PCA9551_LED0 = 0x01, |
| 56 | + PCA9551_LED1 = 0x02, |
| 57 | + PCA9551_LED2 = 0x04, |
| 58 | + PCA9551_LED3 = 0x08, |
| 59 | + PCA9551_LED4 = 0x10, |
| 60 | + PCA9551_LED5 = 0x20, |
| 61 | + PCA9551_LED6 = 0x40, |
| 62 | + PCA9551_LED7 = 0x80, |
| 63 | +}; |
| 64 | + |
| 65 | +/** |
| 66 | + * @brief Specific to PCA9551: Values used by the LED select registers |
| 67 | + * to determine the source of the LED data. |
| 68 | + */ |
| 69 | +enum PCA9551_LED_Output_Settings_t : uint8_t |
| 70 | +{ |
| 71 | + PCA9551_OUTPUT_LOW = 0x00, // LED on |
| 72 | + PCA9551_OUTPUT_HIGH_IMPEDANCE = 0x01, // LED off; default |
| 73 | + PCA9551_OUTPUT_PWM0 = 0x02, // Output blinks at PWM0 rate |
| 74 | + PCA9551_OUTPUT_PWM1 = 0x03, // Output blinks at PWM1 rate |
| 75 | +}; |
| 76 | + |
| 77 | +/** |
| 78 | + * @brief Specific to PCA9551: Control register definition: |
| 79 | + sepcificies which register the operation will target |
| 80 | + */ |
| 81 | +enum PCA9551_Registers_t : uint8_t |
| 82 | +{ |
| 83 | + PCA9551_REGISTER_INPUT = 0x00, // INPUT (read only) input register |
| 84 | + PCA9551_REGISTER_PCS0 = 0x01, // PSC0 (r/w) frequency prescaler 0 |
| 85 | + PCA9551_REGISTER_PWM0 = 0x02, // PWM0 (r/w) PWM register 0 |
| 86 | + PCA9551_REGISTER_PCS1 = 0x03, // PSC1 (r/w) frequency prescaler 1 |
| 87 | + PCA9551_REGISTER_PWM1 = 0x04, // PWM1 (r/w) PWM register 1 |
| 88 | + PCA9551_REGISTER_LS0 = 0x05, // LS0 (r/w) LED0 to LED3 selector |
| 89 | + PCA9551_REGISTER_LS1 = 0x06, // LS1 (r/w) LED4 to LED7 selector |
| 90 | +}; |
| 91 | + |
| 92 | +/** |
| 93 | + * @brief Specific to PCA9551: Helper constants to work with the bits in the |
| 94 | + * PCA9551 registers |
| 95 | + */ |
| 96 | +enum PCA9551_Constants_t : uint8_t |
| 97 | +{ |
| 98 | + // Mask shifted to apply 2-bit settings to a specific LED in the output |
| 99 | + // settings register |
| 100 | + PCA9551_LED_SETTINGS_MASK = 0x03, |
| 101 | + |
| 102 | + // Amount to shift the LED value per LED when walking through the LEDs |
| 103 | + // in the INPUT register (related to PCA9551_LEDS_t above) |
| 104 | + PCA9551_LED_SHIFT_AMOUNT = 0x01, |
| 105 | + |
| 106 | + // Amount to shift the LED Settings MASK per LED when walking through the |
| 107 | + // LEDs in the output settings register (ie, 2 bits at a time) |
| 108 | + PCA9551_LED_SETTINGS_MASK_SHIFT_AMOUNT = 0x02, |
| 109 | + |
| 110 | + // LED Divider: While the INPUT register can contain all 8 LED values |
| 111 | + // (since each value is represented by one bit), the SETTINGS registers |
| 112 | + // (PCA9551_REGISTER_LS0 and PCA9551_REGISTER_LS1) can only cover 4 LEDs |
| 113 | + // each since each setting requires 2 bits. |
| 114 | + // This divisor takes LEDs 4 to 7 and makes them look like LEDs 0 to 3 |
| 115 | + PCA9551_LED_SETTINGS_DIVISOR = 0x80, |
| 116 | +}; |
| 117 | + |
| 118 | +/** |
| 119 | + * @brief Returns the PCA9551 Device's INPUT register which reflects the state |
| 120 | + * of the device's LEDs (aka pins) |
| 121 | + * |
| 122 | + * @param[in] i_target - Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute |
| 123 | + * to run the commands against |
| 124 | + * |
| 125 | + * @param[out] o_led_data - The INPUT register data from the device |
| 126 | + * |
| 127 | + * @return errlHndl_t nullptr on success; non-nullptr on error. |
| 128 | + */ |
| 129 | +errlHndl_t gpioPca9551GetLeds(TARGETING::Target * i_target, |
| 130 | + uint8_t & o_led_data); |
| 131 | + |
| 132 | +/** |
| 133 | + * @brief Sets the given LED (aka pin) of a PCA9551 Device to a certain setting |
| 134 | + * and returns the INPUT register which reflects the state of device's |
| 135 | + * LEDs (aka pins) after the setting has been run |
| 136 | + * |
| 137 | + * @param[in] i_target - Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute |
| 138 | + * to run the commands against |
| 139 | + * |
| 140 | + * @param[in] i_led - The specific LED Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute |
| 141 | + * to run the commands against |
| 142 | + * |
| 143 | + * @param[in] i_setting - the output setting to set the LED to |
| 144 | + * |
| 145 | + * @param[out] o_led_data - The INPUT register data from the device after the |
| 146 | + * 'set' procedure has been run allowing the caller to |
| 147 | + * evaluate if the set actually went through |
| 148 | + * |
| 149 | + * @return errlHndl_t nullptr on success; non-nullptr on error. |
| 150 | + */ |
| 151 | + |
| 152 | +errlHndl_t gpioPca9551SetLed(TARGETING::Target * i_target, |
| 153 | + const PCA9551_LEDS_t i_led, |
| 154 | + const PCA9551_LED_Output_Settings_t i_setting, |
| 155 | + uint8_t & o_led_data); |
| 156 | + |
| 157 | + |
41 | 158 | }; // GPIO NAMESPACE
|
42 | 159 | #endif
|
0 commit comments