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 typedef uint8_t I2S_Item_t;
35
36 struct OutputI2SChannelConfig_t
37 {
38 uint32_t I2SChannelId;
39 gpio_num_t DataPin;
40 void *arg;
41 void (*GetNextIntensityBitSlices) (void*arg, I2S_Item_t * data, uint32_t numSlices) = nullptr;
42 bool IsActive;
43 };
44
45 // must be a multiple of 32
46 #define I2S_NumSendBufferItems 1024
47
48 struct TransmitDmaBuffer_t
49 {
50 alignas (4) lldesc_t header; // must be first
51 #ifdef USE_I2S_DEBUG_COUNTERS
52 alignas (4) uint32_t id;
53 alignas (4) uint32_t UsageCounter;
54 #endif // def USE_I2S_DEBUG_COUNTERS
55 alignas (4) I2S_Item_t data[I2S_NumSendBufferItems];
56 };
57
58private:
59 // array of configuration settings
60 OutputI2SChannelConfig_t OutputI2SSlotConfigs[I2S_MAX_NUM_PORTS];
61
62 // must be more than zero
63 #define I2S_NumSendBuffers 4
64
65 // Class to manage the io device
66 esp_i2s_parallel i2sParallel;
67
68public:
69 c_OutputI2S ();
70 virtual ~c_OutputI2S ();
71
72 void Begin ();
73 void RegisterSlotDevice (OutputI2SChannelConfig_t config, uint32_t * DataBit, uint32_t * DataBitMask);
74 void RemoveSlotDevice (uint32_t I2SChannelId);
75 void GetStatus (ArduinoJson::JsonObject& jsonStatus);
76 void GetDriverName (String &value) { value = F("I2S"); }
77 uint32_t GetNumTimeSlicesForTargetTimeNS (uint32_t BitTimeInNanoSec);
78 void SetOutputState (uint32_t I2SChannelId, bool NewState);
79 void SetGpio (uint32_t I2SChannelId, gpio_num_t NewGpio);
80 void ISR_Handler (void * _TransmitDmaBuffer);
81
82#ifdef USE_I2S_DEBUG_COUNTERS
83 // debug counters
84 struct I2SDebugCounters_t
85 {
86 uint32_t DataTaskcounter = 0;
87 uint32_t IntensityBitsSent = 0;
88 uint32_t IntensityBitsSentLastFrame = 0;
89 uint32_t I2SEntriesTransfered = 0;
90 uint32_t I2SXmtFills = 0;
91 uint32_t ISRpaused = 0;
92 uint32_t WriteToBuffer = 0;
93 uint32_t ISR_handler_count = 0;
94 uint32_t ISR_FillBuffer = 0;
95 uint32_t BufferOwnerFlagError = 0;
96 uint32_t ISR_NullBufferPointer = 0;
97 };
98 I2SDebugCounters_t I2SDebugCounters;
99
100#define I2S_DEBUG_INC_COUNTER(p) (++I2SDebugCounters.p)
101#define I2S_DEBUG_COUNTER(p) (I2SDebugCounters.p)
102
103#else
104
105#define I2S_DEBUG_INC_COUNTER(p)
106#define I2S_DEBUG_COUNTER(p)
107
108#endif // def USE_I2S_DEBUG_COUNTERS
109
110};
111#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