2019.06.24

This commit is contained in:
hnwangkg-ezio 2019-06-24 17:11:43 +08:00
commit 1f82e4a488
2990 changed files with 667957 additions and 444550 deletions

View file

@ -0,0 +1,99 @@
/*****************************************************************************
* | File : DEV_Config.c
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
*----------------
* | This version: V1.0
* | Date : 2019-06-05
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "DEV_Config.h"
/******************************************************************************
function: Initialization pin
parameter:
Info:
******************************************************************************/
static void DEV_GPIOConfig(void)
{
SYSFS_GPIO_Export(EPD_CS_PIN);
SYSFS_GPIO_Export(EPD_DC_PIN);
SYSFS_GPIO_Export(EPD_RST_PIN);
SYSFS_GPIO_Export(EPD_BUSY_PIN);
SYSFS_GPIO_Direction(EPD_CS_PIN, OUT);
SYSFS_GPIO_Direction(EPD_DC_PIN, OUT);
SYSFS_GPIO_Direction(EPD_RST_PIN, OUT);
SYSFS_GPIO_Direction(EPD_BUSY_PIN, IN);
}
void DEV_Delay_us(UWORD xus)
{
for(int j=xus; j > 0; j--);
}
void DEV_Delay_ms(UWORD xms)
{
for(int j=xms; j > 0; j--)
for(int j=xms; j > 0; j--);
}
/******************************************************************************
function: Module Initialize, the BCM2835 library and initialize the pins, SPI protocol
parameter:
Info:
******************************************************************************/
UBYTE DEV_Module_Init(void)
{
DEV_GPIOConfig();
SYSFS_software_spi_begin();
SYSFS_software_spi_setBitOrder(SOFTWARE_SPI_MSBFIRST);
SYSFS_software_spi_setDataMode(SOFTWARE_SPI_Mode0);
SYSFS_software_spi_setClockDivider(SOFTWARE_SPI_CLOCK_DIV4);
return 0;
}
void DEV_SPI_WriteByte(UBYTE value)
{
SYSFS_software_spi_transfer(value);
}
/******************************************************************************
function: Module exits, closes SPI and BCM2835 library
parameter:
Info:
******************************************************************************/
void DEV_Module_Exit(void)
{
SYSFS_software_spi_end();
SYSFS_GPIO_Write(EPD_CS_PIN, LOW);
SYSFS_GPIO_Write(EPD_DC_PIN, LOW);
SYSFS_GPIO_Write(EPD_RST_PIN, LOW);
SYSFS_GPIO_Unexport(EPD_CS_PIN);
SYSFS_GPIO_Unexport(EPD_DC_PIN);
SYSFS_GPIO_Unexport(EPD_RST_PIN);
SYSFS_GPIO_Unexport(EPD_BUSY_PIN);
}

View file

@ -0,0 +1,69 @@
/*****************************************************************************
* | File : DEV_Config.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
*----------------
* | This version: V1.0
* | Date : 2019-06-04
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef _DEV_CONFIG_H_
#define _DEV_CONFIG_H_
#include "sysfs_gpio.h"
#include "sysfs_software_spi.h"
#include <stdint.h>
#include <stdio.h>
/**
* data
**/
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t
/**
* GPIO config
**/
// #define EPD_MOSI_PIN SPI0_MOSI
// #define EPD_SCK_PIN SPI0_SCK
#define EPD_CS_PIN SPI0_CS0
#define EPD_DC_PIN GPIO25
#define EPD_RST_PIN GPIO17
#define EPD_BUSY_PIN GPIO24
/**
* GPIO read and write
**/
#define DEV_Digital_Write(_pin, _value) SYSFS_GPIO_Write(_pin, _value)
#define DEV_Digital_Read(_pin) SYSFS_GPIO_Read(_pin)
/*------------------------------------------------------------------------------------------------------*/
UBYTE DEV_Module_Init(void);
void DEV_Module_Exit(void);
void DEV_Delay_us(UWORD xus);
void DEV_Delay_ms(UWORD xms);
void DEV_SPI_WriteByte(UBYTE value);
#endif

View file

@ -0,0 +1,47 @@
/*****************************************************************************
* | File : Debug.h
* | Author : Waveshare team
* | Function : debug with printf
* | Info :
* Image scanning
* Please use progressive scanning to generate images or fonts
*----------------
* | This version: V2.0
* | Date : 2018-10-30
* | Info :
* 1.USE_DEBUG -> DEBUG, If you need to see the debug information,
* clear the execution: make DEBUG=-DDEBUG
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef __DEBUG_H
#define __DEBUG_H
#include <stdio.h>
#if DEBUG
#define Debug(__info,...) printf("Debug: " __info,##__VA_ARGS__)
#else
#define Debug(__info,...)
#endif
#endif

View file

@ -0,0 +1,152 @@
/*****************************************************************************
* | File : SYSFS_GPIO.c
* | Author : Waveshare team
* | Function : Drive SYSFS_ GPIO
* | Info : Read and write /sys/class/gpio
*----------------
* | This version: V1.0
* | Date : 2019-06-04
* | Info : Basic version
*
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "sysfs_gpio.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int SYSFS_GPIO_Export(int Pin)
{
char buffer[NUM_MAXBUF];
int len;
int fd;
fd = open("/sys/class/gpio/export", O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Export Failed: Pin%d\n", Pin);
return -1;
}
len = snprintf(buffer, NUM_MAXBUF, "%d", Pin);
write(fd, buffer, len);
SYSFS_GPIO_Debug( "Export: Pin%d\r\n", Pin);
close(fd);
return 0;
}
int SYSFS_GPIO_Unexport(int Pin)
{
char buffer[NUM_MAXBUF];
int len;
int fd;
fd = open("/sys/class/gpio/unexport", O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "unexport Failed: Pin%d\n", Pin);
return -1;
}
len = snprintf(buffer, NUM_MAXBUF, "%d", Pin);
write(fd, buffer, len);
SYSFS_GPIO_Debug( "Unexport: Pin%d\r\n", Pin);
close(fd);
return 0;
}
int SYSFS_GPIO_Direction(int Pin, int Dir)
{
const char dir_str[] = "in\0out";
char path[DIR_MAXSIZ];
int fd;
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/direction", Pin);
fd = open(path, O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Set Direction failed: Pin%d\n", Pin);
return -1;
}
if (write(fd, &dir_str[Dir == IN ? 0 : 3], Dir == IN ? 2 : 3) < 0) {
SYSFS_GPIO_Debug("failed to set direction!\r\n");
return -1;
}
if(Dir == IN){
SYSFS_GPIO_Debug("Pin%d:intput\r\n", Pin);
}else{
SYSFS_GPIO_Debug("Pin%d:Output\r\n", Pin);
}
close(fd);
return 0;
}
int SYSFS_GPIO_Read(int Pin)
{
char path[DIR_MAXSIZ];
char value_str[3];
int fd;
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin);
fd = open(path, O_RDONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Read failed Pin%d\n", Pin);
return -1;
}
if (read(fd, value_str, 3) < 0) {
SYSFS_GPIO_Debug( "failed to read value!\n");
return -1;
}
close(fd);
return(atoi(value_str));
}
int SYSFS_GPIO_Write(int Pin, int value)
{
const char s_values_str[] = "01";
char path[DIR_MAXSIZ];
int fd;
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin);
fd = open(path, O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Write failed : Pin%d,value = %d\n", Pin, value);
return -1;
}
if (write(fd, &s_values_str[value == LOW ? 0 : 1], 1) < 0) {
SYSFS_GPIO_Debug( "failed to write value!\n");
return -1;
}
close(fd);
return 0;
}

View file

@ -0,0 +1,84 @@
/*****************************************************************************
* | File : sysfs_gpio.h
* | Author : Waveshare team
* | Function : Drive SC16IS752 GPIO
* | Info : Read and write /sys/class/gpio
*----------------
* | This version: V1.0
* | Date : 2019-06-04
* | Info : Basic version
*
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef __SYSFS_GPIO_
#define __SYSFS_GPIO_
#include <stdio.h>
#define IN 0
#define OUT 1
#define LOW 0
#define HIGH 1
#define NUM_MAXBUF 4
#define DIR_MAXSIZ 60
#define SYSFS_GPIO_DEBUG 1
#if SYSFS_GPIO_DEBUG
#define SYSFS_GPIO_Debug(__info,...) printf("Debug: " __info,##__VA_ARGS__)
#else
#define SYSFS_GPIO_Debug(__info,...)
#endif
// BCM GPIO for Jetson nano
#define GPIO4 216 // 7, 4
#define GPIO17 50 // 11, 17
#define GPIO18 79 // 12, 18
#define GPIO27 14 // 13, 27
#define GPIO22 194 // 15, 22
#define GPIO23 232 // 16, 23
#define GPIO24 15 // 18, 24
#define SPI0_MOSI 16 // 19, 10
#define SPI0_MISO 17 // 21, 9
#define GPIO25 13 // 22, 25
#define SPI0_SCK 18 // 23, 11
#define SPI0_CS0 19 // 24, 8
#define SPI0_CS1 20 // 26, 7
#define GPIO5 149 // 29, 5
#define GPIO6 200 // 31, 6
#define GPIO12 168 // 32, 12
#define GPIO13 38 // 33, 13
#define GPIO19 76 // 35, 19
#define GPIO16 51 // 36, 16
#define GPIO26 12 // 37, 26
#define GPIO20 77 // 38, 20
#define GPIO21 78 // 40, 21
// 22PIN + 2PIN UART0 + 2PIN I2C0 + 2PIN I2C
// + 2PIN 3V3 + 2PIN 5V + 8PIN GND = 40PIN
int SYSFS_GPIO_Export(int Pin);
int SYSFS_GPIO_Unexport(int Pin);
int SYSFS_GPIO_Direction(int Pin, int Dir);
int SYSFS_GPIO_Read(int Pin);
int SYSFS_GPIO_Write(int Pin, int value);
#endif

View file

@ -0,0 +1,204 @@
/*****************************************************************************
* | File : sysfs_software_spi.h
* | Author : Waveshare team
* | Function : Read and write /sys/class/gpio, software spi
* | Info :
*----------------
* | This version: V1.0
* | Date : 2019-06-05
* | Info : Basic version
*
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# Read_data OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "sysfs_software_spi.h"
SOFTWARE_SPI software_spi;
/******************************************************************************
function:
parameter:
Info:
******************************************************************************/
void SYSFS_software_spi_begin(void)
{
// gpio
software_spi.SCLK_PIN = SPI0_SCK;
software_spi.MOSI_PIN = SPI0_MOSI;
software_spi.MISO_PIN = SPI0_MISO;
//software spi configure
software_spi.Mode = SOFTWARE_SPI_Mode0;
software_spi.Type = SOFTWARE_SPI_Master;
software_spi.Delay = SOFTWARE_SPI_CLOCK_DIV2;
software_spi.Order = SOFTWARE_SPI_MSBFIRST; // MSBFIRST
SYSFS_GPIO_Export(software_spi.SCLK_PIN);
SYSFS_GPIO_Export(software_spi.MOSI_PIN);
SYSFS_GPIO_Export(software_spi.MISO_PIN);
SYSFS_GPIO_Direction(software_spi.SCLK_PIN, OUT);
SYSFS_GPIO_Direction(software_spi.MOSI_PIN, OUT);
SYSFS_GPIO_Direction(software_spi.MISO_PIN, IN);
}
void SYSFS_software_spi_end(void)
{
SYSFS_GPIO_Write(software_spi.SCLK_PIN, LOW);
SYSFS_GPIO_Write(software_spi.MOSI_PIN, LOW);
SYSFS_GPIO_Unexport(software_spi.SCLK_PIN);
SYSFS_GPIO_Unexport(software_spi.MOSI_PIN);
}
void SYSFS_software_spi_setBitOrder(uint8_t order)
{
software_spi.Order = order & 1;
}
void SYSFS_software_spi_setDataMode(uint8_t mode)
{
if(mode > 4) {
SYSFS_SOFTWARE_SPI_Debug("MODE must be 0-3\r\n");
return;
}
software_spi.Mode = mode;
switch (software_spi.Mode) {
case SOFTWARE_SPI_Mode0:
software_spi.CPOL = 0;
software_spi.CPHA = 0;
break;
case SOFTWARE_SPI_Mode1:
software_spi.CPOL = 0;
software_spi.CPHA = 1;
break;
case SOFTWARE_SPI_Mode2:
software_spi.CPOL = 1;
software_spi.CPHA = 0;
break;
case SOFTWARE_SPI_Mode3:
software_spi.CPOL = 1;
software_spi.CPHA = 1;
break;
}
}
void SYSFS_software_spi_setClockDivider(uint8_t div)
{
if(div > 8) {
SYSFS_SOFTWARE_SPI_Debug("div must be 0-7\r\n");
return;
}
switch (div) {
case SOFTWARE_SPI_CLOCK_DIV2:
software_spi.Delay = 2;
break;
case SOFTWARE_SPI_CLOCK_DIV4:
software_spi.Delay = 4;
break;
case SOFTWARE_SPI_CLOCK_DIV8:
software_spi.Delay = 8;
break;
case SOFTWARE_SPI_CLOCK_DIV16:
software_spi.Delay = 16;
break;
case SOFTWARE_SPI_CLOCK_DIV32:
software_spi.Delay = 32;
break;
case SOFTWARE_SPI_CLOCK_DIV64:
software_spi.Delay = 64;
break;
case SOFTWARE_SPI_CLOCK_DIV128:
software_spi.Delay = 128;
break;
default:
software_spi.Delay = 128;
break;
}
}
/******************************************************************************
function: SPI Mode 0
parameter:
Info:
******************************************************************************/
uint8_t SYSFS_software_spi_transfer(uint8_t value)
{
// printf("value = %d\r\n", value);
uint8_t Read_data;
if (software_spi.Order == SOFTWARE_SPI_LSBFIRST) {
uint8_t temp =
((value & 0x01) << 7) |
((value & 0x02) << 5) |
((value & 0x04) << 3) |
((value & 0x08) << 1) |
((value & 0x10) >> 1) |
((value & 0x20) >> 3) |
((value & 0x40) >> 5) |
((value & 0x80) >> 7);
value = temp;
}
uint8_t delay = software_spi.Delay >> 1;
for(int j=delay; j > 0; j--);
// printf("value = %d\r\n", value);
uint8_t Read_miso = 0;
SYSFS_GPIO_Write(software_spi.SCLK_PIN, 0);
for (uint8_t bit = 0; bit < 8; bit++) {
SYSFS_GPIO_Write(software_spi.SCLK_PIN, 0);
// for(int j=delay; j > 0; j--);// DELAY
if (software_spi.CPHA) {
Read_miso = SYSFS_GPIO_Read(software_spi.MISO_PIN);
if (software_spi.Order == SOFTWARE_SPI_LSBFIRST) {
Read_data <<= 1;
Read_data |= Read_miso;
} else {
Read_data >>= 1;
Read_data |= Read_miso << 7;
}
} else {
SYSFS_GPIO_Write(software_spi.MOSI_PIN, ((value<<bit) & 0x80) ? HIGH : LOW);
}
// for(int j=delay; j > 0; j--);// DELAY
SYSFS_GPIO_Write(software_spi.SCLK_PIN, 1);
// for(int j=delay; j > 0; j--);// DELAY
if (software_spi.CPHA) {
SYSFS_GPIO_Write(software_spi.MOSI_PIN, ((value<<bit) & 0x80) ? HIGH : LOW);
} else {
Read_miso = SYSFS_GPIO_Read(software_spi.MISO_PIN);
if (software_spi.Order == SOFTWARE_SPI_LSBFIRST) {
Read_data <<= 1;
Read_data |= Read_miso;
} else {
Read_data >>= 1;
Read_data |= Read_miso << 7;
}
}
// for(int j=delay; j > 0; j--);// DELAY
}
return Read_data;
}

View file

@ -0,0 +1,111 @@
/*****************************************************************************
* | File : sysfs_software_spi.h
* | Author : Waveshare team
* | Function : Read and write /sys/class/gpio, software spi
* | Info :
*----------------
* | This version: V1.0
* | Date : 2019-06-05
* | Info : Basic version
*
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef __SYSFS_SOFTWARE_SPI_
#define __SYSFS_SOFTWARE_SPI_
#include "sysfs_gpio.h"
#include <stdint.h>
#include <stdio.h>
#define SYSFS_SOFTWARE_SPI_DEBUG 1
#if SYSFS_SOFTWARE_SPI_DEBUG
#define SYSFS_SOFTWARE_SPI_Debug(__info,...) printf("Debug: " __info,##__VA_ARGS__)
#else
#define SYSFS_SOFTWARE_SPI_Debug(__info,...)
#endif
/**
* SPI communication mode
**/
typedef enum {
SOFTWARE_SPI_Mode0, /* Clock Polarity is 0 and Clock Phase is 0 */
SOFTWARE_SPI_Mode1, /* Clock Polarity is 0 and Clock Phase is 1 */
SOFTWARE_SPI_Mode2, /* Clock Polarity is 1 and Clock Phase is 0 */
SOFTWARE_SPI_Mode3, /* Clock Polarity is 1 and Clock Phase is 1 */
} SOFTWARE_SPI_Mode;
/**
* SPI clock(div)
**/
typedef enum {
SOFTWARE_SPI_CLOCK_DIV2,
SOFTWARE_SPI_CLOCK_DIV4,
SOFTWARE_SPI_CLOCK_DIV8,
SOFTWARE_SPI_CLOCK_DIV16,
SOFTWARE_SPI_CLOCK_DIV32,
SOFTWARE_SPI_CLOCK_DIV64,
SOFTWARE_SPI_CLOCK_DIV128,
} SOFTWARE_SPI_Clock;
/**
* Define SPI type
**/
typedef enum {
SOFTWARE_SPI_Master,
SOFTWARE_SPI_Slave,
} SOFTWARE_SPI_Type;
/**
* Define SPI order
**/
typedef enum {
SOFTWARE_SPI_LSBFIRST,
SOFTWARE_SPI_MSBFIRST,
} SOFTWARE_SPI_Order;
/**
* Define SPI attribute
**/
typedef struct SPIStruct {
//GPIO
uint16_t SCLK_PIN;
uint16_t MOSI_PIN;
uint16_t MISO_PIN;
uint16_t CS_PIN;
//Mode
SOFTWARE_SPI_Mode Mode;
uint8_t CPOL;
uint8_t CPHA;
SOFTWARE_SPI_Clock Delay;
SOFTWARE_SPI_Type Type;
SOFTWARE_SPI_Order Order;
} SOFTWARE_SPI;
void SYSFS_software_spi_begin(void);
void SYSFS_software_spi_end(void);
void SYSFS_software_spi_setBitOrder(uint8_t order);
void SYSFS_software_spi_setDataMode(uint8_t mode);
void SYSFS_software_spi_setClockDivider(uint8_t div);
uint8_t SYSFS_software_spi_transfer(uint8_t value);
#endif