ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputI2S.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputI2S.hpp - I2S driver code for ESPixelStick I2S Channel
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2026 Shelby Merrick
7* http://www.forkineye.com
8*
9* This program is provided free for you to use in any way that you wish,
10* subject to the laws and regulations where you are using it. Due diligence
11* is strongly suggested before using this code. Please give credit where due.
12*
13* The Author makes no warranty of any kind, express or implied, with regard
14* to this program or the documentation contained in this document. The
15* Author shall not be liable in any event for incidental or consequential
16* damages in connection with, or arising out of, the furnishing, performance
17* or use of these programs.
18*
19*/
20
21#ifdef SUPPORT_I2S
22#include "ESPixelStick.h"
23#include "i2s_parallel.hpp"
24#include "driver/gpio.h"
25
26// #define USE_I2S_DEBUG_COUNTERS
27
28class c_OutputI2S
29{
30public:
31 // a slot is one bit in the output item
32 #define I2S_NUM_SLOTA i2s_bits_per_chan_t::I2S_BITS_PER_CHAN_8BIT
33 #define I2S_MAX_NUM_PORTS 8
34
35 typedef byte I2S_Item_t;
36
37 struct OutputI2SChannelConfig_t
38 {
39 uint32_t I2SChannelId;
40 gpio_num_t DataPin;
41 void *arg;
42 bool (*GetNextIntensityBitSlices) (void*arg, I2S_Item_t * data, uint32_t numSlices, I2S_Item_t DefaultIntensitySliceData) = nullptr;
43 void (*StartNewFrame) (void*arg) = nullptr;
44 bool IsActive;
45 bool IdleLevelIsHigh;
46 };
47
48 // must be a multiple of 32 bits (aka 4 bytes)
49 #define I2S_NumSendBufferItems (256 * sizeof(uint32_t))
50
51 struct TransmitDmaBuffer_t
52 {
53 alignas (4) lldesc_t header; // must be first
54 #ifdef USE_I2S_DEBUG_COUNTERS
55 alignas (4) uint32_t id;
56 alignas (4) uint32_t UsageCounter;
57 #endif // def USE_I2S_DEBUG_COUNTERS
58 alignas (4) I2S_Item_t data[I2S_NumSendBufferItems];
59 };
60
61private:
62 // array of configuration settings
63 OutputI2SChannelConfig_t OutputI2SSlotConfigs[I2S_MAX_NUM_PORTS];
64 OutputI2SChannelConfig_t * pCurrentPort = OutputI2SSlotConfigs;
65
66 void ISR_MoveToNextPort();
67
68 // must be more than zero
69 #define I2S_NumSendBuffers 4
70
71 // Class to manage the io device
72 esp_i2s_parallel i2sParallel;
73 I2S_Item_t DefaultIntensitySliceData = I2S_Item_t(-1);
74
75public:
76 c_OutputI2S ();
77 virtual ~c_OutputI2S ();
78
79 void Begin ();
80 void RegisterSlotDevice (OutputI2SChannelConfig_t config, uint32_t * DataBit, uint32_t * DataBitMask);
81 void RemoveSlotDevice (uint32_t I2SChannelId);
82 void GetStatus (ArduinoJson::JsonObject& jsonStatus);
83 void GetDriverName (String &value) { value = F("I2S"); }
84 uint32_t GetNumTimeSlicesForTargetTimeNS (uint32_t BitTimeInNanoSec);
85 void SetOutputState (uint32_t I2SChannelId, bool NewState);
86 void SetGpio (uint32_t I2SChannelId, gpio_num_t NewGpio);
87 void ISR_Handler (void * _TransmitDmaBuffer);
88
89#ifdef USE_I2S_DEBUG_COUNTERS
90 // debug counters
91 struct I2SDebugCounters_t
92 {
93 uint32_t DataTaskcounter = 0;
94 uint32_t IntensityBitsSent = 0;
95 uint32_t IntensityBitsSentLastFrame = 0;
96 uint32_t I2SEntriesTransfered = 0;
97 uint32_t I2SXmtFills = 0;
98 uint32_t ISRpaused = 0;
99 uint32_t WriteToBuffer = 0;
100 uint32_t ISR_handler_count = 0;
101 uint32_t ISR_FillBuffer = 0;
102 uint32_t BufferOwnerFlagError = 0;
103 uint32_t ISR_NullBufferPointer = 0;
104 };
105 I2SDebugCounters_t I2SDebugCounters;
106
107#define I2S_DEBUG_INC_COUNTER(p) (++I2SDebugCounters.p)
108#define I2S_DEBUG_COUNTER(p) (I2SDebugCounters.p)
109
110#else
111
112#define I2S_DEBUG_INC_COUNTER(p)
113#define I2S_DEBUG_COUNTER(p)
114
115#endif // def USE_I2S_DEBUG_COUNTERS
116
117}; // c_OutputI2S
118
119#endif // def #ifdef SUPPORT_I2S
uint8_t header[4]
Definition fseq.h:0
config_t config
Definition main.cpp:98
void GetDriverName(String &Name)
Definition main.cpp:121