-
Notifications
You must be signed in to change notification settings - Fork 0
/
nand_spi.h
74 lines (50 loc) · 2.39 KB
/
nand_spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/************************** NAND SPI Functions ***********************************
Filename: nand_spi.h
Description: Implements SPI wrapper functions for use by low-level drivers.
Uses HAL library for STM32L0 series.
Version: 0.1
Author: Tharun Suresh
********************************************************************************
Version History.
Ver. Date Comments
0.1 Jan 2022 In Development
********************************************************************************
The following functions are available in this library:
********************************************************************************/
#include "stm32l0xx_hal.h"
#define NAND_NCS_PIN GPIO_PIN_12
#define NAND_SCK_PIN GPIO_PIN_13
#define NAND_MISO_PIN GPIO_PIN_14
#define NAND_MOSI_PIN GPIO_PIN_15
#define NAND_MOSI_PORT GPIOB
#define NAND_MISO_PORT GPIOB
#define NAND_SCK_PORT GPIOB
#define NAND_NCS_PORT GPIOB
#define DUMMY_BYTE 0x00
#define NAND_SPI_TIMEOUT 100
/* using custom return type to keep higher layers as platform-agnostic as possible */
typedef enum {
SPI_OK,
SPI_Fail
} NAND_SPI_ReturnType;
/* SPI Transaction Parameters */
typedef struct {
uint8_t *buffer;
uint16_t length;
} SPI_Params;
/******************************************************************************
* Internal Functions
*****************************************************************************/
void __nand_spi_cs_low(void);
void __nand_spi_cs_high(void);
/******************************************************************************
* List of APIs
*****************************************************************************/
/* General functions */
void NAND_Wait(uint8_t milliseconds);
/* Wrapper functions for sending and receiving data */
NAND_SPI_ReturnType NAND_SPI_Send(SPI_HandleTypeDef *hspi, SPI_Params *data_send);
NAND_SPI_ReturnType NAND_SPI_SendReceive(SPI_HandleTypeDef *hspi, SPI_Params *data_send, SPI_Params *data_recv);
NAND_SPI_ReturnType NAND_SPI_Receive(SPI_HandleTypeDef *hspi, SPI_Params *data_recv);
NAND_SPI_ReturnType NAND_SPI_Send_Command_Data(SPI_HandleTypeDef *hspi, SPI_Params *cmd_send, SPI_Params *data_send);
/******************************************************************************/