many changes

This commit is contained in:
kazu
2018-09-22 15:44:26 +02:00
parent 528a00b0e9
commit 90e9fee101
11 changed files with 1581 additions and 476 deletions

View File

@@ -3,6 +3,7 @@
//#include "IO.h"
#include "../Platforms.h"
#include "../Debug.h"
#if (PLATFORM == NODE_MCU) || (PLATFORM == WEMOS_D1_MINI)
@@ -28,31 +29,43 @@
#define SPI_FAST
#elif (PLATFORM == NODE32S)
#elif (PLATFORM == WROOM32_DEVKIT)
#define SPI_CS_OUTPUT GPIO15_OUTPUT_SET
#define SPI_MOSI_OUTPUT GPIO13_OUTPUT_SET
#define SPI_MISO_INPUT GPIO12_INPUT_SET
#define SPI_MISO_NO_PULLUP GPIO12_INPUT_PULLUP_UNSET
#define SPI_CLK_OUTPUT GPIO14_OUTPUT_SET
#include "driver/gpio.h"
#include <stdint.h>
#define SPI_CS_LO GPIO15_L
#define SPI_CS_HI GPIO15_H
#define SPI_PIN_MISO GPIO_NUM_35
#define SPI_PIN_MOSI GPIO_NUM_32
#define SPI_PIN_CLK GPIO_NUM_27
#define SPI_PIN_CS GPIO_NUM_25
#define SPI_CLK_LO GPIO14_L
#define SPI_CLK_HI GPIO14_H
#define SPI_CS_OUTPUT gpio_set_direction(SPI_PIN_CS, GPIO_MODE_OUTPUT)
#define SPI_MOSI_OUTPUT gpio_set_direction(SPI_PIN_MOSI, GPIO_MODE_OUTPUT)
#define SPI_MISO_INPUT gpio_set_direction(SPI_PIN_MISO, GPIO_MODE_INPUT)
#define SPI_MISO_NO_PULLUP //gpio_set_pull_mode(SPI_PIN_MISO, GPIO_FLOATING) /// ??????
#define SPI_CLK_OUTPUT gpio_set_direction(SPI_PIN_CLK, GPIO_MODE_OUTPUT)
#define SPI_MOSI_LO GPIO13_L
#define SPI_MOSI_HI GPIO13_H
#define SPI_CS_LO gpio_set_level(SPI_PIN_CS, 0)
#define SPI_CS_HI gpio_set_level(SPI_PIN_CS, 1)
#define SPI_MISO_READ GPIO12_IN
#define SPI_CLK_LO gpio_set_level(SPI_PIN_CLK, 0)
#define SPI_CLK_HI gpio_set_level(SPI_PIN_CLK, 1)
#define SPI_MOSI_LO gpio_set_level(SPI_PIN_MOSI, 0)
#define SPI_MOSI_HI gpio_set_level(SPI_PIN_MOSI, 1)
#define SPI_MISO_READ gpio_get_level(SPI_PIN_MISO)
#define SPI_FAST
#else
#error "not supported"
#endif
namespace spi {
static constexpr const char* NAME = "SoftSPI";
// MTDI GPIO12 MISO (DIN) D6
// MTCK GPIO13 MOSI (DOUT) D7
// MTMS GPIO14 CLOCK D5
@@ -86,14 +99,14 @@ namespace spi {
__asm__ __volatile__("nop");
}
static inline void waitLong() {
os_delay_us(1);
DELAY_US(1);
}
#else
static inline void wait() {
os_delay_us(2);
DELAY_US(2);
}
static inline void waitLong() {
os_delay_us(50);
DELAY_US(50);
}
#endif
@@ -150,7 +163,8 @@ namespace spi {
static void ICACHE_FLASH_ATTR init() {
static void IN_FLASH init() {
debugMod(NAME, "init()");
SPI_MISO_INPUT; SPI_MISO_NO_PULLUP; // D6: MISO
SPI_MOSI_OUTPUT; // D7: MOSI
SPI_CLK_OUTPUT; // D5: CLK
@@ -159,7 +173,7 @@ namespace spi {
/** read 16 bits */
static uint16_t ICACHE_FLASH_ATTR readWord() {
static uint16_t IN_FLASH readWord() {
return
(readBit() << 15) |
(readBit() << 14) |
@@ -180,7 +194,7 @@ namespace spi {
}
/** read 8 bits */
static uint8_t ICACHE_FLASH_ATTR readByte() {
static uint8_t IN_FLASH readByte() {
return
(readBit() << 7) |
(readBit() << 6) |
@@ -194,7 +208,7 @@ namespace spi {
static void ICACHE_FLASH_ATTR writeWord(const uint16_t word) {
static void IN_FLASH writeWord(const uint16_t word) {
writeBit(word & BIT(15));
writeBit(word & BIT(14));
writeBit(word & BIT(13));
@@ -213,7 +227,7 @@ namespace spi {
writeBit(word & BIT( 0));
}
static void ICACHE_FLASH_ATTR writeByte(const uint8_t byte) {
static void IN_FLASH writeByte(const uint8_t byte) {
writeBit(byte & BIT( 7));
writeBit(byte & BIT( 6));
writeBit(byte & BIT( 5));
@@ -224,7 +238,7 @@ namespace spi {
writeBit(byte & BIT( 0));
}
static uint16 ICACHE_FLASH_ATTR readWriteWord(const uint16_t word) {
static uint16_t IN_FLASH readWriteWord(const uint16_t word) {
return
(readWriteBit(word & BIT(15)) << 15) |
(readWriteBit(word & BIT(14)) << 14) |
@@ -244,7 +258,7 @@ namespace spi {
(readWriteBit(word & BIT( 0)) << 0);
}
static uint8 ICACHE_FLASH_ATTR readWriteByte(const uint8_t byte) {
static uint8_t IN_FLASH readWriteByte(const uint8_t byte) {
return
(readWriteBit(byte & BIT( 7)) << 7) |
(readWriteBit(byte & BIT( 6)) << 6) |