so://phie

libbcm2835

A tiny library for the BCM2835
git clone git://soophie.de/libbcm2835

blob: 11bf26b7643d259f68cc6f49bd7716673250c074 (3811 bytes)[doc][blame][raw]

1/*

2BCM2835 ARM Peripherals

3

4Datasheet:

5https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

6

7

8 3V3 Power *---[ 01 | 02 ]---* 5V Power

9 GPIO2 (SDA) *---[ 03 | 04 ]---* 5V Power

10 GPIO3 (SCL) *---[ 05 | 06 ]---* Ground

11 GPIO4 (GPCLK0) *---[ 07 | 08 ]---* GPIO14 (TXD)

12 Ground *---[ 09 | 10 ]---* GPIO15 (RXD)

13 GPIO17 *---[ 11 | 12 ]---* GPIO18 (PCM_CLK)

14 GPIO27 *---[ 13 | 14 ]---* Ground

15 GPIO22 *---[ 15 | 16 ]---* GPIO23

16 3V3 Power *---[ 17 | 18 ]---* GPIO24

17 GPIO10 (MOSI) *---[ 19 | 20 ]---* Ground

18 GPIO9 (MISO) *---[ 21 | 22 ]---* GPIO25

19 GPIO11 (SCLK) *---[ 23 | 24 ]---* GPIO8 (CE0)

20 Ground *---[ 25 | 26 ]---* GPIO7 (CE1)

21 GPIO0 (ID_SD) *---[ 27 | 28 ]---* GPIO1 (ID_SC)

22 GPIO5 *---[ 29 | 30 ]---* Ground

23 GPIO6 *---[ 31 | 32 ]---* GPIO12 (PWM0)

24 GPIO13 (PWM1) *---[ 33 | 34 ]---* Ground

25GPIO19 (PCM_FS) *---[ 35 | 36 ]---* GPIO16

26 GPIO26 *---[ 37 | 38 ]---* GPIO20 (PCM_DIN)

27 Ground *---[ 39 | 40 ]---* GPIO21 (PCM_DOUT)

28

29

30gpiochip0 - 54 lines:

31

32--------------------- --------------------- ---------------------

33line 00: ID_SDA line 18: GPIO18 line 36: SD1_DATA0

34line 01: ID_SCL line 19: GPIO19 line 37: SD1_DATA1

35line 02: GPIO2 line 20: GPIO20 line 38: SD1_DATA2

36line 03: GPIO3 line 21: GPIO21 line 39: SD1_DATA3

37line 04: GPIO4 line 22: GPIO22 line 40: PWM0_OUT

38line 05: GPIO5 line 23: GPIO23 line 41: PWM1_OUT

39line 06: GPIO6 line 24: GPIO24 line 42: ETH_CLK

40line 07: GPIO7 line 25: GPIO25 line 43: WIFI_CLK

41line 08: GPIO8 line 26: GPIO26 line 44: SDA0

42line 09: GPIO9 line 27: GPIO27 line 45: SCL0

43line 10: GPIO10 line 28: NC line 46: SMPS_SCL

44line 11: GPIO11 line 29: LAN_RUN_BOOT line 47: SMPS_SDA

45line 12: GPIO12 line 30: CTS0 line 48: SD_CLK_R

46line 13: GPIO13 line 31: RTS0 line 49: SD_CMD_R

47line 14: GPIO14 line 32: TXD0 line 50: SD_DATA0_R

48line 15: GPIO15 line 33: RXD0 line 51: SD_DATA1_R

49line 16: GPIO16 line 34: SD1_CLK line 52: SD_DATA2_R

50line 17: GPIO17 line 35: SD1_CMD line 53: SD_DATA3_R

51--------------------- --------------------- ---------------------

52*/

53

54#ifndef BCM_2835_H

55#define BCM_2835_H

56

57#define BCM_FSEL0 0

58#define BCM_FSEL1 1

59#define BCM_FSEL2 2

60#define BCM_FSEL3 3

61#define BCM_FSEL4 4

62#define BCM_FSEL5 5

63#define BCM_SET0 7

64#define BCM_SET1 8

65#define BCM_CLR0 10

66#define BCM_CLR1 11

67#define BCM_LEV0 13

68#define BCM_LEV1 14

69#define BCM_EDS0 16

70#define BCM_EDS1 17

71#define BCM_REN0 19

72#define BCM_REN1 20

73#define BCM_FEN0 22

74#define BCM_FEN1 23

75#define BCM_HEN0 25

76#define BCM_HEN1 26

77#define BCM_LEN0 28

78#define BCM_LEN1 29

79#define BCM_AREN0 31

80#define BCM_AREN1 32

81#define BCM_AFEN0 34

82#define BCM_AFEN1 35

83#define BCM_PUD 37

84#define BCM_PUDCLK0 38

85#define BCM_PUDCLK1 39

86

87#define LOW 0

88#define HIGH 1

89

90typedef unsigned char u8_t;

91typedef unsigned int u32_t;

92

93typedef enum {

94 FSEL_IN = 0x00,

95 FSEL_OUT = 0x01,

96 FSEL_ALT0 = 0x04,

97 FSEL_ALT1 = 0x05,

98 FSEL_ALT2 = 0x06,

99 FSEL_ALT3 = 0x07,

100 FSEL_ALT4 = 0x03,

101 FSEL_ALT5 = 0x02,

102} bcm_fsel_e;

103

104typedef enum {

105 PUD_OFF = 0x00,

106 PUD_DOWN = 0x01,

107 PUD_UP = 0x02,

108} bcm_pud_e;

109

110int bcm_init(void);

111void bcm_fsel(u32_t pin, bcm_fsel_e fsel);

112void bcm_set(u32_t pin);

113void bcm_clr(u32_t pin);

114int bcm_lev(u32_t pin);

115void bcm_pud(u32_t pin, bcm_pud_e pud);

116

117void bcm_write(u32_t pin, int level);

118int bcm_read(u32_t pin);

119void bcm_pulse(u32_t pin, int level, u32_t sleep);

120

121#endif