2021-02-18 12:14:35 +02:00
|
|
|
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-10-06 14:21:30 +03:00
|
|
|
|
|
|
|
#ifndef _SPI_H_INCLUDED
|
|
|
|
#define _SPI_H_INCLUDED
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2017-03-19 11:27:58 +02:00
|
|
|
#include "pins_arduino.h"
|
2016-10-06 14:21:30 +03:00
|
|
|
#include "esp32-hal-spi.h"
|
|
|
|
|
2020-09-30 14:34:37 +03:00
|
|
|
#define SPI_HAS_TRANSACTION
|
|
|
|
|
2016-10-06 14:21:30 +03:00
|
|
|
class SPISettings
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SPISettings() :_clock(1000000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {}
|
|
|
|
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) :_clock(clock), _bitOrder(bitOrder), _dataMode(dataMode) {}
|
|
|
|
uint32_t _clock;
|
|
|
|
uint8_t _bitOrder;
|
|
|
|
uint8_t _dataMode;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SPIClass
|
|
|
|
{
|
2017-02-14 04:15:34 +02:00
|
|
|
private:
|
|
|
|
int8_t _spi_num;
|
|
|
|
spi_t * _spi;
|
|
|
|
bool _use_hw_ss;
|
|
|
|
int8_t _sck;
|
|
|
|
int8_t _miso;
|
|
|
|
int8_t _mosi;
|
|
|
|
int8_t _ss;
|
|
|
|
uint32_t _div;
|
|
|
|
uint32_t _freq;
|
|
|
|
bool _inTransaction;
|
2019-10-14 18:39:27 +01:00
|
|
|
void writePattern_(const uint8_t * data, uint8_t size, uint8_t repeat);
|
2017-02-14 04:15:34 +02:00
|
|
|
|
2016-10-06 14:21:30 +03:00
|
|
|
public:
|
|
|
|
SPIClass(uint8_t spi_bus=HSPI);
|
2017-11-28 11:12:39 +01:00
|
|
|
void begin(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
|
2016-10-06 14:21:30 +03:00
|
|
|
void end();
|
|
|
|
|
|
|
|
void setHwCs(bool use);
|
|
|
|
void setBitOrder(uint8_t bitOrder);
|
|
|
|
void setDataMode(uint8_t dataMode);
|
|
|
|
void setFrequency(uint32_t freq);
|
|
|
|
void setClockDivider(uint32_t clockDiv);
|
2018-05-14 07:08:27 -04:00
|
|
|
|
|
|
|
uint32_t getClockDivider();
|
2016-10-06 14:21:30 +03:00
|
|
|
|
|
|
|
void beginTransaction(SPISettings settings);
|
|
|
|
void endTransaction(void);
|
2018-12-02 18:15:01 +01:00
|
|
|
void transfer(uint8_t * data, uint32_t size);
|
2016-10-06 14:21:30 +03:00
|
|
|
uint8_t transfer(uint8_t data);
|
|
|
|
uint16_t transfer16(uint16_t data);
|
|
|
|
uint32_t transfer32(uint32_t data);
|
2018-12-02 18:15:01 +01:00
|
|
|
|
2019-10-14 18:39:27 +01:00
|
|
|
void transferBytes(const uint8_t * data, uint8_t * out, uint32_t size);
|
2016-10-06 14:21:30 +03:00
|
|
|
void transferBits(uint32_t data, uint32_t * out, uint8_t bits);
|
|
|
|
|
|
|
|
void write(uint8_t data);
|
|
|
|
void write16(uint16_t data);
|
|
|
|
void write32(uint32_t data);
|
2019-09-22 09:36:32 +03:00
|
|
|
void writeBytes(const uint8_t * data, uint32_t size);
|
2017-02-14 11:58:04 +02:00
|
|
|
void writePixels(const void * data, uint32_t size);//ili9341 compatible
|
2019-10-14 18:39:27 +01:00
|
|
|
void writePattern(const uint8_t * data, uint8_t size, uint32_t repeat);
|
2017-02-14 04:15:34 +02:00
|
|
|
|
|
|
|
spi_t * bus(){ return _spi; }
|
2016-10-06 14:21:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern SPIClass SPI;
|
|
|
|
|
|
|
|
#endif
|