WPILibC++ 2024.3.2
AddressableLED.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
10#include "hal/Types.h"
11
12/**
13 * @defgroup hal_addressable Addressable LED Functions
14 * @ingroup hal_capi
15 * @{
16 */
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * Initialize Addressable LED using a PWM Digital handle.
24 *
25 * @param[in] outputPort handle of the digital port for PWM
26 * @param[out] status the error code, or 0 for success
27 * @return Addressable LED handle
28 */
30 HAL_DigitalHandle outputPort, int32_t* status);
31
32/**
33 * Free the Addressable LED Handle.
34 *
35 * @param[in] handle the Addressable LED handle to free
36 */
38
39/**
40 * Set the Addressable LED PWM Digital port.
41 *
42 * @param[in] handle the Addressable LED handle
43 * @param[in] outputPort The digital handle of the PWM port
44 * @param[out] status the error code, or 0 for success
45 */
47 HAL_DigitalHandle outputPort,
48 int32_t* status);
49
50/**
51 * Sets the length of the LED strip.
52 *
53 * <p>The max length is 5460 LEDs.
54 *
55 * @param[in] handle the Addressable LED handle
56 * @param[in] length the strip length
57 * @param[out] status the error code, or 0 for success
58 */
60 int32_t length, int32_t* status);
61
62/**
63 * Sets the led output data.
64 *
65 * <p>If the output is enabled, this will start writing the next data cycle.
66 * It is safe to call, even while output is enabled.
67 *
68 * @param[in] handle the Addressable LED handle
69 * @param[in] data the buffer to write
70 * @param[in] length the strip length
71 * @param[out] status the error code, or 0 for success
72 */
74 const struct HAL_AddressableLEDData* data,
75 int32_t length, int32_t* status);
76
77/**
78 * Sets the bit timing.
79 *
80 * <p>By default, the driver is set up to drive WS2812Bs, so nothing needs to
81 * be set for those.
82 *
83 * @param[in] handle the Addressable LED handle
84 * @param[in] highTime0NanoSeconds high time for 0 bit (default 400ns)
85 * @param[in] lowTime0NanoSeconds low time for 0 bit (default 900ns)
86 * @param[in] highTime1NanoSeconds high time for 1 bit (default 900ns)
87 * @param[in] lowTime1NanoSeconds low time for 1 bit (default 600ns)
88 * @param[out] status the error code, or 0 for success
89 */
91 int32_t highTime0NanoSeconds,
92 int32_t lowTime0NanoSeconds,
93 int32_t highTime1NanoSeconds,
94 int32_t lowTime1NanoSeconds,
95 int32_t* status);
96
97/**
98 * Sets the sync time.
99 *
100 * <p>The sync time is the time to hold output so LEDs enable. Default set for
101 * WS2812B.
102 *
103 * @param[in] handle the Addressable LED handle
104 * @param[in] syncTimeMicroSeconds the sync time (default 280us)
105 * @param[out] status the error code, or 0 for success
106 */
108 int32_t syncTimeMicroSeconds,
109 int32_t* status);
110
111/**
112 * Starts the output.
113 *
114 * <p>The output writes continuously.
115 *
116 * @param[in] handle the Addressable LED handle
117 * @param[out] status the error code, or 0 for success
118 */
120 int32_t* status);
121
122/**
123 * Stops the output.
124 *
125 * @param[in] handle the Addressable LED handle
126 * @param[out] status the error code, or 0 for success
127 */
129 int32_t* status);
130
131#ifdef __cplusplus
132} // extern "C"
133#endif
134/** @} */
void HAL_SetAddressableLEDSyncTime(HAL_AddressableLEDHandle handle, int32_t syncTimeMicroSeconds, int32_t *status)
Sets the sync time.
void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle, HAL_DigitalHandle outputPort, int32_t *status)
Set the Addressable LED PWM Digital port.
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle, int32_t length, int32_t *status)
Sets the length of the LED strip.
void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle, const struct HAL_AddressableLEDData *data, int32_t length, int32_t *status)
Sets the led output data.
void HAL_StopAddressableLEDOutput(HAL_AddressableLEDHandle handle, int32_t *status)
Stops the output.
void HAL_StartAddressableLEDOutput(HAL_AddressableLEDHandle handle, int32_t *status)
Starts the output.
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(HAL_DigitalHandle outputPort, int32_t *status)
Initialize Addressable LED using a PWM Digital handle.
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle)
Free the Addressable LED Handle.
void HAL_SetAddressableLEDBitTiming(HAL_AddressableLEDHandle handle, int32_t highTime0NanoSeconds, int32_t lowTime0NanoSeconds, int32_t highTime1NanoSeconds, int32_t lowTime1NanoSeconds, int32_t *status)
Sets the bit timing.
HAL_Handle HAL_DigitalHandle
Definition: Types.h:31
HAL_Handle HAL_AddressableLEDHandle
Definition: Types.h:61
structure for holding one LED's color data.
Definition: AddressableLEDTypes.h:13