ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputSpi.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputSpi.h - SPI driver code for ESPixelStick Spi Channel
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2015, 2024 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* This is a derived class that converts data in the output buffer into
20* pixel intensities and then transmits them through the configured serial
21* interface.
22*
23*/
24
25#include "ESPixelStick.h"
26#ifdef SUPPORT_SPI_OUTPUT
27
28#include "OutputPixel.hpp"
29#include <driver/spi_master.h>
30#include <esp_task.h>
31#if defined(SUPPORT_OutputType_GRINCH)
32 #include "OutputGrinch.hpp"
33#endif // defined(SUPPORT_OutputType_GRINCH)
34
35class c_OutputSpi
36{
37public:
38 // These functions are inherited from c_OutputCommon
39 c_OutputSpi ();
40 virtual ~c_OutputSpi ();
41
42 // functions to be provided by the derived class
43 void Begin (c_OutputPixel* _OutputPixel);
44#if defined(SUPPORT_OutputType_GRINCH)
45 void Begin (c_OutputGrinch* _OutputSerial);
46#endif // defined(SUPPORT_OutputType_GRINCH)
47 bool Poll ();
48 TaskHandle_t GetTaskHandle () { return SendIntensityDataTaskHandle; }
49 void GetDriverName (String& Name) { Name = CN_OutputSpi; }
50 void DataOutputTask (void* pvParameters);
51 void SendIntensityData ();
52 bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
53 void GetConfig (ArduinoJson::JsonObject & jsonConfig);
54
55 uint32_t DataTaskcounter = 0;
56 uint32_t DataCbCounter = 0;
57
58private:
59
60#define SPI_SPI_MASTER_FREQ_1M (APB_CLK_FREQ/80) // 1Mhz
61#define SPI_NUM_TRANSACTIONS 2
62#define SPI_NUM_INTENSITY_PER_TRANSACTION 128
63#define SPI_BITS_PER_INTENSITY 8
64#define SPI_SPI_HOST DEFAULT_SPI_DEVICE
65#define SPI_SPI_DMA_CHANNEL 2
66
67 bool ISR_MoreDataToSend();
68 bool ISR_GetNextIntensityToSend(uint32_t& Data);
69 void StartNewFrame();
70
71 uint8_t NumIntensityValuesPerInterrupt = 0;
72 uint8_t NumIntensityBitsPerInterrupt = 0;
73 spi_device_handle_t spi_device_handle = 0;
74
75 // uint32_t FrameStartCounter = 0;
76 uint32_t SendIntensityDataCounter = 0;
77 // uint32_t FrameDoneCounter = 0;
78 // uint32_t FrameEndISRcounter = 0;
79
80 byte * TransactionBuffers[SPI_NUM_TRANSACTIONS];
81 spi_transaction_t Transactions[SPI_NUM_TRANSACTIONS];
82 uint8_t NextTransactionToFill = 0;
83 TaskHandle_t SendIntensityDataTaskHandle = NULL;
84
85#ifndef DEFAULT_SPI_CS_GPIO
86# define DEFAULT_SPI_CS_GPIO gpio_num_t(-1)
87#endif // ndef DEFAULT_SPI_CS_GPIO
88
89 gpio_num_t DataPin = DEFAULT_SPI_DATA_GPIO;
90 gpio_num_t ClockPin = DEFAULT_SPI_CLOCK_GPIO;
91 gpio_num_t CsPin = DEFAULT_SPI_CS_GPIO;
92
93 c_OutputPixel* OutputPixel = nullptr;
94#if defined(SUPPORT_OutputType_GRINCH)
95 c_OutputGrinch * OutputGrinch = nullptr;
96#endif // defined(SUPPORT_OutputType_GRINCH)
97
98#ifndef HasBeenInitialized
99 bool HasBeenInitialized = false;
100#endif // ndef HasBeenInitialized
101
102}; // c_OutputSpi
103
104#endif // def SUPPORT_SPI_OUTPUT
const CN_PROGMEM char CN_OutputSpi[]
Definition ConstNames.cpp:153
#define DEFAULT_SPI_CLOCK_GPIO
Definition GPIO_Defs_ESP32_BreakDanceV2.hpp:30
#define DEFAULT_SPI_CS_GPIO
Definition GPIO_Defs_ESP32_BreakDanceV2.hpp:31
#define DEFAULT_SPI_DATA_GPIO
Definition GPIO_Defs_ESP32_BreakDanceV2.hpp:29
Definition OutputPixel.hpp:28
void GetDriverName(String &Name)
Definition main.cpp:115
void GetConfig(JsonObject &json)
Definition main.cpp:440
void SetConfig(const char *DataString)
Definition main.cpp:286