waveshare_epaper

Waveshare e-paper display shenanigans
git clone git://bsandro.tech/waveshare_epaper
Log | Files | Refs | README

sysfs_software_spi.h (3323B)


      1 /*****************************************************************************
      2 * | File        :   sysfs_software_spi.h
      3 * | Author      :   Waveshare team
      4 * | Function    :   Read and write /sys/class/gpio, software spi
      5 * | Info        :
      6 *----------------
      7 * |	This version:   V1.0
      8 * | Date        :   2019-06-05
      9 * | Info        :   Basic version
     10 *
     11 #
     12 # Permission is hereby granted, free of charge, to any person obtaining a copy
     13 # of this software and associated documnetation files (the "Software"), to deal
     14 # in the Software without restriction, including without limitation the rights
     15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     16 # copies of the Software, and to permit persons to  whom the Software is
     17 # furished to do so, subject to the following conditions:
     18 #
     19 # The above copyright notice and this permission notice shall be included in
     20 # all copies or substantial portions of the Software.
     21 #
     22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     24 # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     25 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     26 # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     28 # THE SOFTWARE.
     29 #
     30 ******************************************************************************/
     31 #ifndef __SYSFS_SOFTWARE_SPI_
     32 #define __SYSFS_SOFTWARE_SPI_
     33 
     34 #include "sysfs_gpio.h"
     35 #include <stdint.h>
     36 #include <stdio.h>
     37 
     38 #define SYSFS_SOFTWARE_SPI_DEBUG 1
     39 #if SYSFS_SOFTWARE_SPI_DEBUG
     40 #define SYSFS_SOFTWARE_SPI_Debug(__info,...) printf("Debug: " __info,##__VA_ARGS__)
     41 #else
     42 #define SYSFS_SOFTWARE_SPI_Debug(__info,...)
     43 #endif
     44 
     45 /**
     46  * SPI communication mode
     47 **/
     48 typedef enum {
     49     SOFTWARE_SPI_Mode0,   /* Clock Polarity is 0 and Clock Phase is 0 */
     50     SOFTWARE_SPI_Mode1,   /* Clock Polarity is 0 and Clock Phase is 1 */
     51     SOFTWARE_SPI_Mode2,   /* Clock Polarity is 1 and Clock Phase is 0 */
     52     SOFTWARE_SPI_Mode3,   /* Clock Polarity is 1 and Clock Phase is 1 */
     53 } SOFTWARE_SPI_Mode;
     54 
     55 /**
     56  * SPI clock(div)
     57 **/
     58 typedef enum {
     59     SOFTWARE_SPI_CLOCK_DIV2,
     60     SOFTWARE_SPI_CLOCK_DIV4,
     61     SOFTWARE_SPI_CLOCK_DIV8,
     62     SOFTWARE_SPI_CLOCK_DIV16,
     63     SOFTWARE_SPI_CLOCK_DIV32,
     64     SOFTWARE_SPI_CLOCK_DIV64,
     65     SOFTWARE_SPI_CLOCK_DIV128,
     66 } SOFTWARE_SPI_Clock;
     67 
     68 /**
     69  * Define SPI type
     70 **/
     71 typedef enum {
     72     SOFTWARE_SPI_Master,
     73     SOFTWARE_SPI_Slave,
     74 } SOFTWARE_SPI_Type;
     75 
     76 /**
     77  * Define SPI order
     78 **/
     79 typedef enum {    
     80     SOFTWARE_SPI_LSBFIRST,
     81     SOFTWARE_SPI_MSBFIRST,
     82 } SOFTWARE_SPI_Order;
     83 
     84 /**
     85  * Define SPI attribute
     86 **/
     87 typedef struct SPIStruct {
     88     //GPIO
     89     uint16_t SCLK_PIN;
     90     uint16_t MOSI_PIN;
     91     uint16_t MISO_PIN;
     92     uint16_t CS_PIN;
     93     
     94     //Mode
     95     SOFTWARE_SPI_Mode Mode;
     96     uint8_t CPOL;
     97     uint8_t CPHA;
     98 
     99     SOFTWARE_SPI_Clock Delay;
    100     SOFTWARE_SPI_Type Type;
    101     SOFTWARE_SPI_Order Order;
    102 } SOFTWARE_SPI;
    103 
    104 void SYSFS_software_spi_begin(void);
    105 void SYSFS_software_spi_end(void);
    106 void SYSFS_software_spi_setBitOrder(uint8_t order);
    107 void SYSFS_software_spi_setDataMode(uint8_t mode);
    108 void SYSFS_software_spi_setClockDivider(uint8_t div);
    109 uint8_t SYSFS_software_spi_transfer(uint8_t value);
    110 
    111 #endif