ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_spi.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ___FW_SPI_H___
16#define ___FW_SPI_H___
17
18#include "fw_conf.h"
19#include "fw_types.h"
20
33typedef enum
34{
35 // SS MOSI MISO SCLK
42
43typedef enum
44{
50
51typedef enum
52{
53 SPI_ClockPhase_LeadingEdge = 0x00, // Bits are sampled on the leading edge of SCLK
54 SPI_ClockPhase_TrailingEdge = 0x01, // Bits are sampled on the trailing edge of SCLK
56
57typedef enum
58{
59 SPI_DataOrder_MSB = 0x00, // High bits first
60 SPI_DataOrder_LSB = 0x01, // Low bits first
62
63#define SPI_RxTxFinished() (SPSTAT & 0x80)
64#define SPI_ClearInterrupt() SFR_SET(SPSTAT, 7)
65#define SPI_ClearWriteConflictInterrupt() SFR_SET(SPSTAT, 6)
66#define SPI_ClearInterrupts() (SPSTAT |= 0xC0)
67
68#define SPI_IgnoreSlaveSelect(__STATE__) SFR_ASSIGN(SPCTL, 7, __STATE__)
69#define SPI_SetEnabled(__STATE__) SFR_ASSIGN(SPCTL, 6, __STATE__)
70#define SPI_SetDataOrder(__ORDER__) SFR_ASSIGN(SPCTL, 5, __ORDER__)
71#define SPI_SetMasterMode(__STATE__) SFR_ASSIGN(SPCTL, 4, __STATE__)
72
78#define SPI_SetClockPolarity(__STATE__) SFR_ASSIGN(SPCTL, 3, __STATE__)
84#define SPI_SetClockPhase(__PHASE__) SFR_ASSIGN(SPCTL, 2, __PHASE__)
88#define SPI_SetClockPrescaler(__PRE_SCALER__) (SPCTL = SPCTL & ~0x03 | ((__PRE_SCALER__) << 0))
92#define SPI_SetPort(__ALTER_PORT__) (P_SW1 = P_SW1 & ~(0x03 << 2) | ((__ALTER_PORT__) << 2))
93
95void SPI_TxRxBytes(uint8_t *pBuf, uint8_t len);
96
97#endif
__CODE int8_t dat[20]
SPI_ClockPreScaler_t
Definition: fw_spi.h:44
@ SPI_ClockPreScaler_4
Definition: fw_spi.h:45
@ SPI_ClockPreScaler_8
Definition: fw_spi.h:46
@ SPI_ClockPreScaler_32or2
Definition: fw_spi.h:48
@ SPI_ClockPreScaler_16
Definition: fw_spi.h:47
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20
void SPI_TxRxBytes(uint8_t *pBuf, uint8_t len)
Definition: fw_spi.c:28
SPI_ClockPhase_t
Definition: fw_spi.h:52
@ SPI_ClockPhase_TrailingEdge
Definition: fw_spi.h:54
@ SPI_ClockPhase_LeadingEdge
Definition: fw_spi.h:53
SPI_AlterPort_t
Definition: fw_spi.h:34
@ SPI_AlterPort_P22_P23_P24_P25
Definition: fw_spi.h:37
@ SPI_AlterPort_P35_P34_P33_P32
Definition: fw_spi.h:39
@ SPI_AlterPort_8G1K08_8Pin
Definition: fw_spi.h:40
@ SPI_AlterPort_P54_P40_P41_P43
Definition: fw_spi.h:38
@ SPI_AlterPort_P12P54_P13_P14_P15
Definition: fw_spi.h:36
SPI_DataOrder_t
Definition: fw_spi.h:58
@ SPI_DataOrder_LSB
Definition: fw_spi.h:60
@ SPI_DataOrder_MSB
Definition: fw_spi.h:59
unsigned char uint8_t
Definition: fw_types.h:18