Skip to content

Commit 1274de9

Browse files
committed
[update]添加了 spi gpio 的hal实例
1 parent 6dfe8f9 commit 1274de9

4 files changed

Lines changed: 179 additions & 0 deletions

File tree

‎L2_Core/hal/inc/ek_hal_gpio.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef EK_HAL_GPIO_H
2+
#define EK_HAL_GPIO_H
3+
4+
#include "../../utils/inc/ek_def.h"
5+
#include "../../utils/inc/ek_list.h"
6+
7+
typedef struct ek_hal_gpio_t ek_hal_gpio_t;
8+
9+
struct ek_hal_gpio_t
10+
{
11+
uint8_t idx;
12+
ek_list_node_t node;
13+
14+
void (*set)(void);
15+
void (*reset)(void);
16+
void (*toggle)(void);
17+
};
18+
19+
extern ek_list_node_t ek_hal_gpio_head;
20+
21+
extern ek_hal_gpio_t hal_drv_gpio_xxx_pin;
22+
23+
void ek_hal_gpio_init(void);
24+
25+
#endif // EK_HAL_GPIO_H

‎L2_Core/hal/inc/ek_hal_spi.h‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef EK_HAL_SPI_H
2+
#define EK_HAL_SPI_H
3+
4+
#include "../../utils/inc/ek_def.h"
5+
#include "../../utils/inc/ek_list.h"
6+
7+
typedef struct ek_hal_spi_t ek_hal_spi_t;
8+
9+
struct ek_hal_spi_t
10+
{
11+
uint8_t idx;
12+
ek_list_node_t node;
13+
14+
bool lock;
15+
16+
void (*init)(void);
17+
bool (*write)(uint8_t *txdata, size_t size);
18+
bool (*read)(uint8_t *rxdata, size_t size);
19+
bool (*write_read)(uint8_t *txdata, uint8_t *rxdata, size_t size);
20+
};
21+
22+
extern ek_list_node_t ek_hal_spi_head;
23+
24+
extern ek_hal_spi_t hal_drv_spi1;
25+
26+
void ek_hal_spi_init(void);
27+
28+
#endif // EK_HAL_SPI_H

‎L2_Core/hal/src/ek_hal_gpio.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "../inc/ek_hal_gpio.h"
2+
#include "../inc/ek_export.h"
3+
4+
ek_list_node_t ek_hal_gpio_head;
5+
6+
static void xxx_pin_set(vopd);
7+
static void xxx_pin_reset(vopd);
8+
static void xxx_pin_toggle(vopd);
9+
10+
ek_hal_gpio_t hal_drv_gpio_xxx_pin = {
11+
.idx = 1,
12+
.reset = xxx_pin_set,
13+
.set = xxx_pin_reset,
14+
.toggle = xxx_pin_toggle,
15+
};
16+
17+
static void xxx_pin_set(vopd)
18+
{
19+
}
20+
21+
static void xxx_pin_reset(vopd)
22+
{
23+
}
24+
25+
static void xxx_pin_toggle(vopd)
26+
{
27+
}
28+
29+
void ek_hal_gpio_init(void)
30+
{
31+
ek_list_init(&ek_hal_gpio_head);
32+
ek_list_add_tail(&ek_hal_gpio_head, &hal_drv_gpio_xxx_pin.node);
33+
}
34+
35+
EK_EXPORT(ek_hal_gpio_init, 0);

‎L2_Core/hal/src/ek_hal_spi.c‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include "../inc/ek_hal_spi.h"
2+
#include "../../utils/inc/ek_assert.h"
3+
#include "../inc/ek_export.h"
4+
5+
#define EK_HAL_LOCK_ON(x) ((x)->lock = true)
6+
#define EK_HAL_LOCK_OFF(x) ((x)->lock = false)
7+
#define EK_HAL_LOCK_TEST(x) ((x)->lock == true)
8+
9+
#define STM32F429XX_TIMEOUT (100)
10+
11+
ek_list_node_t ek_hal_spi_head;
12+
13+
static void spi1_init(void);
14+
static bool spi1_send(uint8_t *txdata, size_t size);
15+
static bool spi1_recieve(uint8_t *rxdata, size_t size);
16+
static bool spi1_write_recieve(uint8_t *txdata, uint8_t *rxdata, size_t size);
17+
18+
ek_hal_spi_t hal_drv_spi1 = {
19+
.idx = 1,
20+
.lock = false,
21+
22+
.init = spi1_init,
23+
.read = spi1_recieve,
24+
.write = spi1_send,
25+
.write_read = spi1_write_recieve,
26+
};
27+
28+
static void spi1_init(void)
29+
{
30+
hal_drv_spi1.lock = false;
31+
32+
ek_list_add_tail(&ek_hal_spi_head, &hal_drv_spi1.node);
33+
}
34+
35+
static bool spi1_send(uint8_t *txdata, size_t size)
36+
{
37+
if (EK_HAL_LOCK_TEST(&hal_drv_spi1)) return false;
38+
39+
EK_HAL_LOCK_ON(&hal_drv_spi1);
40+
41+
__UNUSED(txdata);
42+
__UNUSED(size);
43+
44+
EK_HAL_LOCK_OFF(&hal_drv_spi1);
45+
46+
return true;
47+
}
48+
49+
static bool spi1_recieve(uint8_t *rxdata, size_t size)
50+
{
51+
if (EK_HAL_LOCK_TEST(&hal_drv_spi1)) return false;
52+
53+
EK_HAL_LOCK_ON(&hal_drv_spi1);
54+
55+
__UNUSED(rxdata);
56+
__UNUSED(size);
57+
58+
EK_HAL_LOCK_OFF(&hal_drv_spi1);
59+
60+
return true;
61+
}
62+
63+
static bool spi1_write_recieve(uint8_t *txdata, uint8_t *rxdata, size_t size)
64+
{
65+
if (EK_HAL_LOCK_TEST(&hal_drv_spi1)) return false;
66+
67+
EK_HAL_LOCK_ON(&hal_drv_spi1);
68+
69+
__UNUSED(txdata);
70+
__UNUSED(rxdata);
71+
__UNUSED(size);
72+
73+
EK_HAL_LOCK_OFF(&hal_drv_spi1);
74+
75+
return true;
76+
}
77+
78+
void ek_hal_spi_init(void)
79+
{
80+
ek_list_node_t *p;
81+
ek_list_init(&ek_hal_spi_head);
82+
83+
spi1_init();
84+
85+
ek_list_iterate(p, &ek_hal_spi_head)
86+
{
87+
ek_hal_spi_t *spi = (ek_hal_spi_t *)ek_list_container(p, ek_hal_spi_t, node);
88+
}
89+
}
90+
91+
EK_EXPORT(ek_hal_spi_init, 0);

0 commit comments

Comments
 (0)