Skip to content

Commit f333dca

Browse files
committed
raspi4 spi0 driver can run
1 parent 7e5373e commit f333dca

File tree

9 files changed

+470
-26
lines changed

9 files changed

+470
-26
lines changed

bsp/raspberry-pi/raspi4-32/.config

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,19 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
134134
# CONFIG_RT_USING_I2C is not set
135135
CONFIG_RT_USING_PIN=y
136136
# CONFIG_RT_USING_ADC is not set
137+
# CONFIG_RT_USING_DAC is not set
137138
# CONFIG_RT_USING_PWM is not set
138139
# CONFIG_RT_USING_MTD_NOR is not set
139140
# CONFIG_RT_USING_MTD_NAND is not set
140141
# CONFIG_RT_USING_PM is not set
141142
# CONFIG_RT_USING_RTC is not set
142143
# CONFIG_RT_USING_SDIO is not set
143-
# CONFIG_RT_USING_SPI is not set
144+
CONFIG_RT_USING_SPI=y
145+
# CONFIG_RT_USING_QSPI is not set
146+
# CONFIG_RT_USING_SPI_MSD is not set
147+
# CONFIG_RT_USING_SFUD is not set
148+
# CONFIG_RT_USING_ENC28J60 is not set
149+
# CONFIG_RT_USING_SPI_WIFI is not set
144150
# CONFIG_RT_USING_WDT is not set
145151
# CONFIG_RT_USING_AUDIO is not set
146152
# CONFIG_RT_USING_SENSOR is not set
@@ -475,6 +481,10 @@ CONFIG_BSP_USING_GIC=y
475481
CONFIG_BSP_USING_GIC400=y
476482
# CONFIG_BSP_USING_GIC500 is not set
477483
CONFIG_BSP_USING_PIN=y
484+
CONFIG_BSP_USING_SPI=y
485+
CONFIG_BSP_USING_SPI0_BUS=y
486+
CONFIG_BSP_USING_SPI0_DEVICE0=y
487+
# CONFIG_BSP_USING_SPI0_DEVICE1 is not set
478488
CONFIG_BSP_USING_CORETIMER=y
479489
# CONFIG_BSP_USING_SYSTIMER is not set
480490
# CONFIG_BSP_USING_WDT is not set

bsp/raspberry-pi/raspi4-32/driver/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ menu "Hardware Drivers Config"
5050
select RT_USING_PIN
5151
default y
5252

53+
menuconfig BSP_USING_SPI
54+
bool "Enable SPI"
55+
select RT_USING_SPI
56+
default n
57+
58+
if BSP_USING_SPI
59+
config BSP_USING_SPI0_BUS
60+
bool "Enable SPI0 BUS"
61+
default n
62+
config BSP_USING_SPI0_DEVICE0
63+
bool "Enable SPI0 DEVICE0"
64+
select BSP_USING_SPI0_BUS
65+
default n
66+
config BSP_USING_SPI0_DEVICE1
67+
bool "Enable SPI0 DEVICE1"
68+
select BSP_USING_SPI0_BUS
69+
default n
70+
endif
71+
5372
config BSP_USING_CORETIMER
5473
bool "Using core timer"
5574
select RT_USING_CORETIMER

bsp/raspberry-pi/raspi4-32/driver/SConscript

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ cwd = GetCurrentDir()
44
src = Glob('*.c') + Glob('*.cpp')
55
CPPPATH = [cwd, str(Dir('#'))]
66

7-
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
7+
group = DefineGroup('driver', src, depend = [''], CPPPATH = CPPPATH)
8+
9+
# build for sub-directory
10+
list = os.listdir(cwd)
11+
objs = []
12+
13+
for d in list:
14+
path = os.path.join(cwd, d)
15+
if os.path.isfile(os.path.join(path, 'SConscript')):
16+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
17+
group = group + objs
818

919
Return('group')

bsp/raspberry-pi/raspi4-32/driver/drv_gpio.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,34 @@ void prev_raspi_pin_mode(GPIO_PIN pin, GPIO_FUNC mode)
120120
raspi_set_pin_state(fselnum, gpfsel);
121121
}
122122

123+
void prev_raspi_pin_write(GPIO_PIN pin, int pin_value)
124+
{
125+
uint32_t num = pin / 32;
126+
127+
if(num == 0)
128+
{
129+
if(pin_value == 1)
130+
{
131+
GPIO_REG_GPSET0(GPIO_BASE) = 1 << (pin % 32);
132+
}
133+
else
134+
{
135+
GPIO_REG_GPCLR0(GPIO_BASE) = 1 << (pin % 32);
136+
}
137+
}
138+
else
139+
{
140+
if(pin_value == 1)
141+
{
142+
GPIO_REG_GPSET1(GPIO_BASE) = 1 << (pin % 32);
143+
}
144+
else
145+
{
146+
GPIO_REG_GPCLR1(GPIO_BASE) = 1 << (pin % 32);
147+
}
148+
}
149+
}
150+
123151
static void raspi_pin_mode(struct rt_device *dev, rt_base_t pin, rt_base_t mode)
124152
{
125153
GPIO_FUNC raspi_mode = OUTPUT;
@@ -149,30 +177,7 @@ static void raspi_pin_mode(struct rt_device *dev, rt_base_t pin, rt_base_t mode)
149177

150178
static void raspi_pin_write(struct rt_device *dev, rt_base_t pin, rt_base_t value)
151179
{
152-
uint32_t num = pin / 32;
153-
154-
if(num == 0)
155-
{
156-
if(value == 0)
157-
{
158-
GPIO_REG_GPSET0(GPIO_BASE) = 1 << (pin % 32);
159-
}
160-
else
161-
{
162-
GPIO_REG_GPCLR0(GPIO_BASE) = 1 << (pin % 32);
163-
}
164-
}
165-
else
166-
{
167-
if(value == 0)
168-
{
169-
GPIO_REG_GPSET1(GPIO_BASE) = 1 << (pin % 32);
170-
}
171-
else
172-
{
173-
GPIO_REG_GPCLR1(GPIO_BASE) = 1 << (pin % 32);
174-
}
175-
}
180+
prev_raspi_pin_write(pin, value);
176181
}
177182

178183
static int raspi_pin_read(struct rt_device *device, rt_base_t pin)

bsp/raspberry-pi/raspi4-32/driver/drv_gpio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ typedef enum {
134134
} GPIO_PUPD_FUNC;
135135

136136
void prev_raspi_pin_mode(GPIO_PIN pin, GPIO_FUNC mode);
137+
void prev_raspi_pin_write(GPIO_PIN pin, int pin_value);
137138
int rt_hw_gpio_init(void);
138139

139140
#endif /* __DRV_GPIO_H__ */

0 commit comments

Comments
 (0)