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 ARDUINO_ARCH_ESP32
27
28#include "OutputPixel.hpp"
29#include <driver/spi_master.h>
30#include <esp_task.h>
31#if defined(SUPPORT_OutputProtocol_GRINCH)
32 #include "OutputGrinch.hpp"
33#endif // defined(SUPPORT_OutputProtocol_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 (OM_OutputPortDefinition_t & OutputPortDefinition, c_OutputPixel* _OutputPixel);
44#if defined(SUPPORT_OutputProtocol_GRINCH)
45 void Begin (OM_OutputPortDefinition_t & OutputPortDefinition, c_OutputGrinch* _OutputSerial);
46#endif // defined(SUPPORT_OutputProtocol_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 OM_OutputPortDefinition_t OutputPortDefinition;
61
62#define SPI_SPI_MASTER_FREQ_1M (APB_CLK_FREQ/80) // 1Mhz
63#define SPI_NUM_TRANSACTIONS 2
64#define SPI_NUM_INTENSITY_PER_TRANSACTION 128
65#define SPI_BITS_PER_INTENSITY 8
66#define SPI_SPI_HOST DEFAULT_SPI_DEVICE
67#define SPI_SPI_DMA_CHANNEL 2
68
69 bool ISR_MoreDataToSend();
70 bool ISR_GetNextIntensityToSend(uint32_t& Data);
71 void StartNewFrame();
72
73 uint8_t NumIntensityValuesPerInterrupt = 0;
74 uint8_t NumIntensityBitsPerInterrupt = 0;
75 spi_device_handle_t spi_device_handle = 0;
76
77 // uint32_t FrameStartCounter = 0;
78 uint32_t SendIntensityDataCounter = 0;
79 // uint32_t FrameDoneCounter = 0;
80 // uint32_t FrameEndISRcounter = 0;
81
82 byte * TransactionBuffers[SPI_NUM_TRANSACTIONS];
83 spi_transaction_t Transactions[SPI_NUM_TRANSACTIONS];
84 uint8_t NextTransactionToFill = 0;
85 TaskHandle_t SendIntensityDataTaskHandle = NULL;
86
87#ifndef DEFAULT_SPI_CS_GPIO
88# define DEFAULT_SPI_CS_GPIO gpio_num_t(-1)
89#endif // ndef DEFAULT_SPI_CS_GPIO
90
91 c_OutputPixel* OutputPixel = nullptr;
92#if defined(SUPPORT_OutputProtocol_GRINCH)
93 c_OutputGrinch * OutputGrinch = nullptr;
94#endif // defined(SUPPORT_OutputProtocol_GRINCH)
95
96#ifndef HasBeenInitialized
97 bool HasBeenInitialized = false;
98#endif // ndef HasBeenInitialized
99
100}; // c_OutputSpi
101
102#endif // def ARDUINO_ARCH_ESP32
const CN_PROGMEM char CN_OutputSpi[]
Definition ConstNames.cpp:165
Definition OutputPixel.hpp:28
void GetDriverName(String &Name)
Definition main.cpp:121
void GetConfig(JsonObject &json)
Definition main.cpp:499
void SetConfig(const char *DataString)
Definition main.cpp:321
Definition OutputMgrPortDefs.hpp:90