ISKBoard example project
Wenxue
2025-09-02 797ac99ec7dbcd43426c2fdc4ccf0c77e0b68843
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**********************************************************************
*   Copyright: (C)2024 LingYun IoT System Studio
*      Author: GuoWenxue<guowenxue@gmail.com>
* Description: ISKBoard Hardware Abstract Layer driver
*
*   ChangeLog:
*        Version    Date       Author            Description
*        V1.0.0  2024.08.29    GuoWenxue      Release initial version
***********************************************************************/
 
#include "stm32l4xx_hal.h"
 
#ifndef __MISCDEV_H
#define __MISCDEV_H
 
#include <stdio.h>
 
/* 定义ON/OFF两个宏,这样在代码中使用比 1/0 更具有可读性 */
#define OFF    0
#define ON     1
 
/* 定义一个gpio的结构体,用来描述这个引脚的相关信息 */
typedef struct gpio_s
{
    const char         *name;
    GPIO_TypeDef       *group;
    uint16_t            pin;
    uint8_t             status;
} gpio_t;
 
/*
 *+----------------------+
 *|    GPIO Relay API    |
 *+----------------------+
 */
 
typedef enum
{
    Relay1,
    RelayMax,
} relaynum_t;
 
 
/* Initial relays GPIO port */
extern int init_relay(void);
 
/* Turn $which r to $status(ON/OFF) */
extern void turn_relay(int which, int status);
 
/* Get $which relay current status */
extern int status_relay(int which);
 
/*
 *+----------------------+
 *|     GPIO Led API     |
 *+----------------------+
 */
 
/* 定义了一个枚举,分别表示RGB三个灯的索引:
 * 枚举的第1个成员,如果没赋值则其值为0,后面的成员值永远是前面成员的值加1.
 */
typedef enum
{
    Led_R, /* 其值为0 */
    Led_G, /* 其值为1 */
    Led_B, /* 其值为2 */
    LedMax,/* 其值为3,刚好是Led的总数 */
} lednum_t;
#define BITMASK_ALLLED  ((1<<LedMax)-1)
 
 
/* Initial leds GPIO port */
extern int init_led(void);
 
/* Turn $which led to $status(ON/OFF) */
extern void turn_led(int which, int status);
 
/* Toggle $which led status */
extern void toggle_led(int which);
 
/* Blink $which led */
extern void blink_led(int which, uint32_t interval);
 
/* Get $which led current status */
extern int status_led(int which);
 
/*
 *+----------------------------+
 *| ADC noisy & lux sensor API |
 *+----------------------------+
 */
 
enum
{
    ADCCHN_NOISY,
    ADCCHN_LUX,
    ADCCHN_MAX,
};
 
extern int adc_sample_lux_noisy(uint32_t *lux, uint32_t *noisy);
 
/*
 *+----------------------------+
 *|  Timer Buzzer/delay API    |
 *+----------------------------+
 */
 
/* Max to 60000 us */
extern void udelay(uint16_t us);
 
/* Turn buzzer on for $times */
extern void beep_start(uint16_t times, uint16_t interval);
 
#endif /* __MISCDEV_H */