constants(3)
π constants π
okay bestie, welcome to constants(3) β straight out of the Library Functions Manual fr fr π
β¨ NAME β¨
constants β the constants you pass to library functions, and the constants you get back from them π«Ά
no cap, that's the whole vibe of this page: it's your lil directory of all the named values that go into library calls and come out of them. iykyk π
more parts are coming, so don't go anywhere β we're just getting started β¨π¦
πΈ SYNOPSIS πΈ
okay so. this page does not ease you in. it just tips the entire dictionary onto your desk and goes "there bestie, memorize." π
everything below is a macro from the library's header β literally every name it answers to, paired with the exact number it's hiding. do not retype these by hand, just #include the header and let it cook. π
β¨ Macros β¨
π the baby ones
#define HIGH 0x1
#define LOW 0x0
#define MIN(a, b) (a < b ? a : b)
HIGH and LOW are the two moods. MIN(a, b) is the tiniest "whichever's smaller, babe" macro β and yes, the double space inside the argument list is literally in the source, leave it alone, it's part of the aesthetic. π
then the clock + address lore drops:
#define BCM2835_CORE_CLK_HZ 250000000
#define BMC2835_RPI2_DT_FILENAME '/proc/device-tree/soc/ranges'
#define BCM2835_PERI_BASE 0x20000000
#define BCM2835_PERI_SIZE 0x01000000
#define BCM2835_RPI2_PERI_BASE 0x3F000000
#define BCM2835_RPI4_PERI_BASE 0xFE000000
#define BCM2835_RPI4_PERI_SIZE 0x01800000
not me clocking thatBMC2835_RPI2_DT_FILENAMEis genuinely spelledBMCand notBCM. that is not my typo, that is the actual name, no cap. spell it exactly like that or the compiler will simply not know her. π
πΊοΈ where everything lives (the base addresses)
this is the map, bestie. every peripheral gets a little plot of memory and these are the street numbers. π‘
#define BCM2835_ST_BASE 0x3000
#define BCM2835_GPIO_PADS 0x100000
#define BCM2835_CLOCK_BASE 0x101000
#define BCM2835_GPIO_BASE 0x200000
#define BCM2835_SPI0_BASE 0x204000
#define BCM2835_BSC0_BASE 0x205000
#define BCM2835_GPIO_PWM 0x20C000
#define BCM2835_AUX_BASE 0x215000
#define BCM2835_SPI1_BASE 0x215080
#define BCM2835_SPI2_BASE 0x2150C0
#define BCM2835_BSC1_BASE 0x804000
#define BCM2835_SMI_BASE 0x600000
#define BCM2835_PAGE_SIZE (4*1024)
#define BCM2835_BLOCK_SIZE (4*1024)
PAGE_SIZE and BLOCK_SIZE are both (4*1024), so yes, they're twins. matching. slay. β¨
π the GPIO register wall
this is the big one, the main character. forty-ish defines of pure GPIO energy. every single one, exactly as written, zero skips: π«Ά
#define BCM2835_GPFSEL0 0x0000
#define BCM2835_GPFSEL1 0x0004
#define BCM2835_GPFSEL2 0x0008
#define BCM2835_GPFSEL3 0x000c
#define BCM2835_GPFSEL4 0x0010
#define BCM2835_GPFSEL5 0x0014
#define BCM2835_GPSET0 0x001c
#define BCM2835_GPSET1 0x0020
#define BCM2835_GPCLR0 0x0028
#define BCM2835_GPCLR1 0x002c
#define BCM2835_GPLEV0 0x0034
#define BCM2835_GPLEV1 0x0038
#define BCM2835_GPEDS0 0x0040
#define BCM2835_GPEDS1 0x0044
#define BCM2835_GPREN0 0x004c
#define BCM2835_GPREN1 0x0050
#define BCM2835_GPFEN0 0x0058
#define BCM2835_GPFEN1 0x005c
#define BCM2835_GPHEN0 0x0064
#define BCM2835_GPHEN1 0x0068
#define BCM2835_GPLEN0 0x0070
#define BCM2835_GPLEN1 0x0074
#define BCM2835_GPAREN0 0x007c
#define BCM2835_GPAREN1 0x0080
#define BCM2835_GPAFEN0 0x0088
#define BCM2835_GPAFEN1 0x008c
#define BCM2835_GPPUD 0x0094
#define BCM2835_GPPUDCLK0 0x0098
#define BCM2835_GPPUDCLK1 0x009c
#define BCM2835_GPPUPPDN0 0x00e4 /* Pin pull-up/down for pins 15:0 */
#define BCM2835_GPPUPPDN1 0x00e8 /* Pin pull-up/down for pins 31:16 */
#define BCM2835_GPPUPPDN2 0x00ec /* Pin pull-up/down for pins 47:32 */
#define BCM2835_GPPUPPDN3 0x00f0 /* Pin pull-up/down for pins 57:48 */
#define BCM2835_GPIO_PUD_ERROR 0x08
the last four come with their own little pinned-on notes about which pins they cover β 15:0, 31:16, 47:32, 57:48 β keep them attached, they're load-bearing. π
π the pads (yes, pads)
#define BCM2835_PADS_GPIO_0_27 0x002c
#define BCM2835_PADS_GPIO_28_45 0x0030
#define BCM2835_PADS_GPIO_46_53 0x0034
#define BCM2835_PAD_PASSWRD (0x5A << 24)
#define BCM2835_PAD_SLEW_RATE_UNLIMITED 0x10
#define BCM2835_PAD_HYSTERESIS_ENABLED 0x08
#define BCM2835_PAD_DRIVE_2mA 0x00
#define BCM2835_PAD_DRIVE_4mA 0x01
#define BCM2835_PAD_DRIVE_6mA 0x02
#define BCM2835_PAD_DRIVE_8mA 0x03
#define BCM2835_PAD_DRIVE_10mA 0x04
#define BCM2835_PAD_DRIVE_12mA 0x05
#define BCM2835_PAD_DRIVE_14mA 0x06
#define BCM2835_PAD_DRIVE_16mA 0x07
a whole lil ladder of drive strengths from 2mA all the way up to 16mA, each one counting up by exactly one. the way that's so satisfying. π
π¦ AUX, the side-quest peripheral
#define BCM2835_AUX_IRQ 0x0000
#define BCM2835_AUX_ENABLE 0x0004
#define BCM2835_AUX_ENABLE_UART1 0x01
#define BCM2835_AUX_ENABLE_SPI0 0x02
#define BCM2835_AUX_ENABLE_SPI1 0x04
#define BCM2835_AUX_SPI_CNTL0 0x0000
#define BCM2835_AUX_SPI_CNTL1 0x0004
#define BCM2835_AUX_SPI_STAT 0x0008
#define BCM2835_AUX_SPI_PEEK 0x000C
#define BCM2835_AUX_SPI_IO 0x0020
#define BCM2835_AUX_SPI_TXHOLD 0x0030
#define BCM2835_AUX_SPI_CLOCK_MIN 30500
#define BCM2835_AUX_SPI_CLOCK_MAX 125000000
then the CNTL0 bit zoo β speeds, chip selects, phase, polarity, all of it:
#define BCM2835_AUX_SPI_CNTL0_SPEED 0xFFF00000
#define BCM2835_AUX_SPI_CNTL0_SPEED_MAX 0xFFF
#define BCM2835_AUX_SPI_CNTL0_SPEED_SHIFT 20
#define BCM2835_AUX_SPI_CNTL0_CS0_N 0x000C0000
#define BCM2835_AUX_SPI_CNTL0_CS1_N 0x000A0000
#define BCM2835_AUX_SPI_CNTL0_CS2_N 0x00060000
#define BCM2835_AUX_SPI_CNTL0_POSTINPUT 0x00010000
#define BCM2835_AUX_SPI_CNTL0_VAR_CS 0x00008000
#define BCM2835_AUX_SPI_CNTL0_VAR_WIDTH 0x00004000
#define BCM2835_AUX_SPI_CNTL0_DOUTHOLD 0x00003000
#define BCM2835_AUX_SPI_CNTL0_ENABLE 0x00000800
#define BCM2835_AUX_SPI_CNTL0_CPHA_IN 0x00000400
#define BCM2835_AUX_SPI_CNTL0_CLEARFIFO 0x00000200
#define BCM2835_AUX_SPI_CNTL0_CPHA_OUT 0x00000100
#define BCM2835_AUX_SPI_CNTL0_CPOL 0x00000080
#define BCM2835_AUX_SPI_CNTL0_MSBF_OUT 0x00000040
#define BCM2835_AUX_SPI_CNTL0_SHIFTLEN 0x0000003F
and CNTL1:
#define BCM2835_AUX_SPI_CNTL1_CSHIGH 0x00000700
#define BCM2835_AUX_SPI_CNTL1_IDLE 0x00000080
#define BCM2835_AUX_SPI_CNTL1_TXEMPTY 0x00000040
#define BCM2835_AUX_SPI_CNTL1_MSBF_IN 0x00000002
#define BCM2835_AUX_SPI_CNTL1_KEEP_IN 0x00000001
and the status crew, who will absolutely be telling you how it's going:
#define BCM2835_AUX_SPI_STAT_TX_LVL 0xF0000000
#define BCM2835_AUX_SPI_STAT_RX_LVL 0x00F00000
#define BCM2835_AUX_SPI_STAT_TX_FULL 0x00000400
#define BCM2835_AUX_SPI_STAT_TX_EMPTY 0x00000200
#define BCM2835_AUX_SPI_STAT_RX_FULL 0x00000100
#define BCM2835_AUX_SPI_STAT_RX_EMPTY 0x00000080
#define BCM2835_AUX_SPI_STAT_BUSY 0x00000040
#define BCM2835_AUX_SPI_STAT_BITCOUNT 0x0000003F
π₯ SPI0, the main SPI
#define BCM2835_SPI0_CS 0x0000
#define BCM2835_SPI0_FIFO 0x0004
#define BCM2835_SPI0_CLK 0x0008
#define BCM2835_SPI0_DLEN 0x000c
#define BCM2835_SPI0_LTOH 0x0010
#define BCM2835_SPI0_DC 0x0014
#define BCM2835_SPI0_CS_LEN_LONG 0x02000000
#define BCM2835_SPI0_CS_DMA_LEN 0x01000000
#define BCM2835_SPI0_CS_CSPOL2 0x00800000
#define BCM2835_SPI0_CS_CSPOL1 0x00400000
#define BCM2835_SPI0_CS_CSPOL0 0x00200000
#define BCM2835_SPI0_CS_RXF 0x00100000
#define BCM2835_SPI0_CS_RXR 0x00080000
#define BCM2835_SPI0_CS_TXD 0x00040000
#define BCM2835_SPI0_CS_RXD 0x00020000
#define BCM2835_SPI0_CS_DONE 0x00010000
#define BCM2835_SPI0_CS_TE_EN 0x00008000
#define BCM2835_SPI0_CS_LMONO 0x00004000
#define BCM2835_SPI0_CS_LEN 0x00002000
#define BCM2835_SPI0_CS_REN 0x00001000
#define BCM2835_SPI0_CS_ADCS 0x00000800
#define BCM2835_SPI0_CS_INTR 0x00000400
#define BCM2835_SPI0_CS_INTD 0x00000200
#define BCM2835_SPI0_CS_DMAEN 0x00000100
#define BCM2835_SPI0_CS_TA 0x00000080
#define BCM2835_SPI0_CS_CSPOL 0x00000040
#define BCM2835_SPI0_CS_CLEAR 0x00000030
#define BCM2835_SPI0_CS_CLEAR_RX 0x00000020
#define BCM2835_SPI0_CS_CLEAR_TX 0x00000010
#define BCM2835_SPI0_CS_CPOL 0x00000008
#define BCM2835_SPI0_CS_CPHA 0x00000004
#define BCM2835_SPI0_CS_CS 0x00000003
the way CS_CLEAR is 0x00000030 and then CLEAR_RX is 0x00000020 and CLEAR_TX is 0x00000010 β it's giving "one mask, two bits" and it's correct. π
π§ BSC (the IΒ²C girlies)
#define BCM2835_BSC_C 0x0000
#define BCM2835_BSC_S 0x0004
#define BCM2835_BSC_DLEN 0x0008
#define BCM2835_BSC_A 0x000c
#define BCM2835_BSC_FIFO 0x0010
#define BCM2835_BSC_DIV 0x0014
#define BCM2835_BSC_DEL 0x0018
#define BCM2835_BSC_CLKT 0x001c
#define BCM2835_BSC_C_I2CEN 0x00008000
#define BCM2835_BSC_C_INTR 0x00000400
#define BCM2835_BSC_C_INTT 0x00000200
#define BCM2835_BSC_C_INTD 0x00000100
#define BCM2835_BSC_C_ST 0x00000080
#define BCM2835_BSC_C_CLEAR_1 0x00000020
#define BCM2835_BSC_C_CLEAR_2 0x00000010
#define BCM2835_BSC_C_READ 0x00000001
#define BCM2835_BSC_S_CLKT 0x00000200
#define BCM2835_BSC_S_ERR 0x00000100
#define BCM2835_BSC_S_RXF 0x00000080
#define BCM2835_BSC_S_TXE 0x00000040
#define BCM2835_BSC_S_RXD 0x00000020
#define BCM2835_BSC_S_TXD 0x00000010
#define BCM2835_BSC_S_RXR 0x00000008
#define BCM2835_BSC_S_TXW 0x00000004
#define BCM2835_BSC_S_DONE 0x00000002
#define BCM2835_BSC_S_TA 0x00000001
#define BCM2835_BSC_FIFO_SIZE 16
#define BCM2835_AUX_SPI_FIFO_SIZE 4
two FIFO sizes at the bottom, 16 for BSC and 4 for the AUX SPI, because they are not the same girl and should not be treated as the same girl. π
π SMI, the deep lore
these ones come with their own inline doc comments, so i'm passing them straight through β every /*! < β¦ > */ preserved, every weird spacing intact, because that's how she wrote them:
#define BCM2835_SMI_CS 0 /*! < Control and status register > */
#define BCM2835_SMI_LENGTH 1 /*! < Transfer length register > */
#define BCM2835_SMI_ADRS 2 /*! < Transfer address register > */
#define BCM2835_SMI_DATA 3 /*! < Transfer data register > */
#define BCM2835_SMI_READ0 4 /*! < Read settings 0 register > */
#define BCM2835_SMI_WRITE0 5 /*! < Write settings 0 register > */
#define BCM2835_SMI_READ1 6 /*! < Read settings 1 register > */
#define BCM2835_SMI_WRITE1 7 /*! < Write settings 1 register > */
#define BCM2835_SMI_READ2 8 /*! < Read settings 2 register > */
#define BCM2835_SMI_WRITE2 9 /*! < Write settings 2 register > */
#define BCM2835_SMI_READ3 10 /*! < Read settings 3 register > */
#define BCM2835_SMI_WRITE3 11 /*! < Write settings 3 register > */
#define BCM2835_SMI_DMAC 12 /*! < DMA control register > */
#define BCM2835_SMI_DIRCS 13 /*! < Direct control register > */
#define BCM2835_SMI_DIRADDR 14 /*! < Direct access address register > */
#define BCM2835_SMI_DIRDATA 15 /*! < Direct access data register > */
note how READ0 through READ3 each have two spaces before "settings" in the comment, while the WRITE ones have one. that's not me being chaotic, that's the source being chaotic. matching energy. π
now the read/write bit fields:
#define BCM2835_SMI_RW_WIDTH_MSK 0xC0000000 /*! < Data width mask > */
#define BCM2835_SMI_RW_WID8 0x00000000 /*! < Data width 8 bits > */
#define BCM2835_SMI_RW_WID16 0x40000000 /*! < Data width 16 bits > */
#define BCM2835_SMI_RW_WID18 0x80000000 /*! < Data width 18 bits > */
#define BCM2835_SMI_RW_WID9 0xC0000000 /*! < Data width 9 bits > */
#define BCM2835_SMI_RW_SETUP_MSK 0x3F000000 /*! < Setup cycles (6 bits) > */
#define BCM2835_SMI_RW_SETUP_LS 24 /*! < Shift for setup cycles > */
#define BCM2835_SMI_RW_MODE68 0x00800000 /*! < Run cycle motorola mode > */
#define BCM2835_SMI_RW_MODE80 0x00000000 /*! < Run cycle intel mode > */
#define BCM2835_SMI_READ_FSETUP 0x00400000 /*! < Read : Setup only for first cycle > */
#define BCM2835_SMI_WRITE_SWAP 0x00400000 /*! < Write : swap pixel data > */
#define BCM2835_SMI_RW_HOLD_MSK 0x003F0000 /*! < Hold cycles (6 bits) > */
#define BCM2835_SMI_RW_HOLD_LS 16 /*! < Shift for hold cycles > */
#define BCM2835_SMI_RW_PACEALL 0x00008000 /*! < Apply pacing always > */
#define BCM2835_SMI_RW_PACE_MSK 0x00007F00 /*! < Pace cycles (7 bits) > */
#define BCM2835_SMI_RW_PACE_LS 8 /*! < Shift for pace cycles > */
#define BCM2835_SMI_RW_DREQ 0x00000080 /*! < Use DMA req on read/write > */
#define BCM2835_SMI_RW_STROBE_MSK 0x0000007F /*! < Strobe cycles (7 bits) > */
#define BCM2835_SMI_RW_STROBE_LS 0 /*! < Shift for strobe cycles > */
READ_FSETUP and WRITE_SWAP are both 0x00400000 β same number, different meaning depending on which way the data's going. it's giving "shared address, twin destinies". π¦
and finally the direct-control flags:
#define BCM2835_SMI_DIRCS_ENABLE 0x00000001 /*! < Set to enable SMI. 0 = Read from ext. devices > */
#define BCM2835_SMI_DIRCS_START 0x00000002 /*! < Initiate SMI transfer > */
#define BCM2835_SMI_DIRCS_DONE 0x00000004 /*! < Set if transfer has finished / Write to clear flag > */
heads up bestie: DIRCS_DONE is a read-to-check, write-to-clear flag. so if you're just sitting there reading it and wondering why it never goes away β yeah, you have to write to it. that's not a bug, that's the deal. π
those three all use two spaces before their comment, unlike basically everything else on this page. i don't make the rules. i just report them. β¨
BCM2835_SMI_DIRCS_WRITE=0x00000008β 1 = write out to ext. devices π€BCM2835_SMI_DIRADRS_DEV_MSK=0x00000300β the mask for the timing configuration slot ποΈBCM2835_SMI_DIRADRS_DEV_LS=8β how far you shift to get at that configuration slotBCM2835_SMI_DIRADRS_DEV0=0x00000000β use timing config slot 0 πBCM2835_SMI_DIRADRS_DEV1=0x00000100β use timing config slot 1BCM2835_SMI_DIRADRS_DEV2=0x00000200β use timing config slot 2BCM2835_SMI_DIRADRS_DEV3=0x00000300β use timing config slot 3BCM2835_SMI_DIRADRS_MSK=0x0000003Fβ adress bits SA5..SA0 (yes bestie, the original really spells it "Adress", we do not correct the ancestors π)BCM2835_SMI_DIRADRS_LS=0β shift for the address bitsSMICLK_CNTL=(44)β /* =0xB0*/ ποΈSMICLK_DIV=(45)β /* =0xB4*/BCM2835_ST_CS=0x0000BCM2835_ST_CLO=0x0004BCM2835_ST_CHI=0x0008
β¨ Enumerations β¨
Okay this is the part where the library hands you a menu of vibes and you just pick one. Each one is a type you pass to a specific function, so clock the typedef names, they're the receipts π§Ύ
enum bcm2835RegisterBaseβ register bases forbcm2835_regbase(). Typedef'd asbcm2835RegisterBase.
enum bcm2835RegisterBase {
BCM2835_REGBASE_ST = 1,
BCM2835_REGBASE_GPIO = 2,
BCM2835_REGBASE_PWM = 3,
BCM2835_REGBASE_CLK = 4,
BCM2835_REGBASE_PADS = 5,
BCM2835_REGBASE_SPI0 = 6,
BCM2835_REGBASE_BSC0 = 7,
BCM2835_REGBASE_BSC1 = 8,
BCM2835_REGBASE_AUX = 9,
BCM2835_REGBASE_SPI1 = 10,
BCM2835_REGBASE_SMI = 11
};
enum bcm2835FunctionSelectβ port function select modes forbcm2835_gpio_fsel(). Typedef'd asbcm2835PortFunction.
enum bcm2835FunctionSelect {
BCM2835_GPIO_FSEL_INPT = 0x00,
BCM2835_GPIO_FSEL_OUTP = 0x01,
BCM2835_GPIO_FSEL_ALT0 = 0x04,
BCM2835_GPIO_FSEL_ALT1 = 0x05,
BCM2835_GPIO_FSEL_ALT2 = 0x06,
BCM2835_GPIO_FSEL_ALT3 = 0x07,
BCM2835_GPIO_FSEL_ALT4 = 0x03,
BCM2835_GPIO_FSEL_ALT5 = 0x02,
BCM2835_GPIO_FSEL_MASK = 0x07
};
Not me noticingALT4andALT5are0x03and0x02whileALT3is0x07π the numbering is NOT in order bestie, do not assume, just use the names.
enum bcm2835PUDControlβ pullup/pulldown defines forbcm2835_gpio_pud(). Typedef'd asbcm2835PUDControl.
enum bcm2835PUDControl {
BCM2835_GPIO_PUD_OFF = 0x00,
BCM2835_GPIO_PUD_DOWN = 0x01,
BCM2835_GPIO_PUD_UP = 0x02
};
enum bcm2835PadGroupβ pad group specification forbcm2835_gpio_pad(). Typedef'd asbcm2835PadGroup.
enum bcm2835PadGroup {
BCM2835_PAD_GROUP_GPIO_0_27 = 0,
BCM2835_PAD_GROUP_GPIO_28_45 = 1,
BCM2835_PAD_GROUP_GPIO_46_53 = 2
};
enum RPiGPIOPinβ GPIO pin numbers. This one is LONG, it's giving phone book energy, but every single one is here fr fr π
enum RPiGPIOPin {
RPI_GPIO_P1_03 = 0,
RPI_GPIO_P1_05 = 1,
RPI_GPIO_P1_07 = 4,
RPI_GPIO_P1_08 = 14,
RPI_GPIO_P1_10 = 15,
RPI_GPIO_P1_11 = 17,
RPI_GPIO_P1_12 = 18,
RPI_GPIO_P1_13 = 21,
RPI_GPIO_P1_15 = 22,
RPI_GPIO_P1_16 = 23,
RPI_GPIO_P1_18 = 24,
RPI_GPIO_P1_19 = 10,
RPI_GPIO_P1_21 = 9,
RPI_GPIO_P1_22 = 25,
RPI_GPIO_P1_23 = 11,
RPI_GPIO_P1_24 = 8,
RPI_GPIO_P1_26 = 7,
RPI_V2_GPIO_P1_03 = 2,
RPI_V2_GPIO_P1_05 = 3,
RPI_V2_GPIO_P1_07 = 4,
RPI_V2_GPIO_P1_08 = 14,
RPI_V2_GPIO_P1_10 = 15,
RPI_V2_GPIO_P1_11 = 17,
RPI_V2_GPIO_P1_12 = 18,
RPI_V2_GPIO_P1_13 = 27,
RPI_V2_GPIO_P1_15 = 22,
RPI_V2_GPIO_P1_16 = 23,
RPI_V2_GPIO_P1_18 = 24,
RPI_V2_GPIO_P1_19 = 10,
RPI_V2_GPIO_P1_21 = 9,
RPI_V2_GPIO_P1_22 = 25,
RPI_V2_GPIO_P1_23 = 11,
RPI_V2_GPIO_P1_24 = 8,
RPI_V2_GPIO_P1_26 = 7,
RPI_V2_GPIO_P1_29 = 5,
RPI_V2_GPIO_P1_31 = 6,
RPI_V2_GPIO_P1_32 = 12,
RPI_V2_GPIO_P1_33 = 13,
RPI_V2_GPIO_P1_35 = 19,
RPI_V2_GPIO_P1_36 = 16,
RPI_V2_GPIO_P1_37 = 26,
RPI_V2_GPIO_P1_38 = 20,
RPI_V2_GPIO_P1_40 = 21,
RPI_V2_GPIO_P5_03 = 28,
RPI_V2_GPIO_P5_04 = 29,
RPI_V2_GPIO_P5_05 = 30,
RPI_V2_GPIO_P5_06 = 31,
RPI_BPLUS_GPIO_J8_03 = 2,
RPI_BPLUS_GPIO_J8_05 = 3,
RPI_BPLUS_GPIO_J8_07 = 4,
RPI_BPLUS_GPIO_J8_08 = 14,
RPI_BPLUS_GPIO_J8_10 = 15,
RPI_BPLUS_GPIO_J8_11 = 17,
RPI_BPLUS_GPIO_J8_12 = 18,
RPI_BPLUS_GPIO_J8_13 = 27,
RPI_BPLUS_GPIO_J8_15 = 22,
RPI_BPLUS_GPIO_J8_16 = 23,
RPI_BPLUS_GPIO_J8_18 = 24,
RPI_BPLUS_GPIO_J8_19 = 10,
RPI_BPLUS_GPIO_J8_21 = 9,
RPI_BPLUS_GPIO_J8_22 = 25,
RPI_BPLUS_GPIO_J8_23 = 11,
RPI_BPLUS_GPIO_J8_24 = 8,
RPI_BPLUS_GPIO_J8_26 = 7,
RPI_BPLUS_GPIO_J8_29 = 5,
RPI_BPLUS_GPIO_J8_31 = 6,
RPI_BPLUS_GPIO_J8_32 = 12,
RPI_BPLUS_GPIO_J8_33 = 13,
RPI_BPLUS_GPIO_J8_35 = 19,
RPI_BPLUS_GPIO_J8_36 = 16,
RPI_BPLUS_GPIO_J8_37 = 26,
RPI_BPLUS_GPIO_J8_38 = 20,
RPI_BPLUS_GPIO_J8_40 = 21
};
enum bcm2835SPIBitOrderβ SPI bit order: specifies the SPI data bit ordering forbcm2835_spi_setBitOrder(). Typedef'd asbcm2835SPIBitOrder.
enum bcm2835SPIBitOrder {
BCM2835_SPI_BIT_ORDER_LSBFIRST = 0,
BCM2835_SPI_BIT_ORDER_MSBFIRST = 1
};
enum bcm2835SPIModeβ SPI data mode: specifies the SPI data mode to hand over tobcm2835_spi_setDataMode().
enum bcm2835SPIMode {
BCM2835_SPI_MODE0 = 0,
BCM2835_SPI_MODE1 = 1,
BCM2835_SPI_MODE2 = 2,
BCM2835_SPI_MODE3 = 3
};
enum bcm2835SPIChipSelectβ specify the SPI chip select pin(s). Typedef'd asbcm2835SPIChipSelect.
enum bcm2835SPIChipSelect {
BCM2835_SPI_CS0 = 0,
BCM2835_SPI_CS1 = 1,
BCM2835_SPI_CS2 = 2,
BCM2835_SPI_CS_NONE = 3
};
enum bcm2835SPIClockDividerβ the divider used to generate the SPI clock from the system clock. Typedef'd asbcm2835SPIClockDivider. The figures below give the divider, clock period and clock frequency. Clock divided is based on nominal core clock rate of250MHzon RPi1 and RPi2, and400MHzon RPi3. It is reported that (contrary to the documentation) any even divider may be used. The frequencies shown for each divider have been confirmed by measurement on RPi1 and RPi2. The system clock frequency on RPi3 is different, so the frequency you get from a given divider will be different. See comments in 'SPI Pins' for information about reliable SPI speeds. Note: it is possible to change the core clock rate of the RPi 3 back to250MHz, by putting
enum bcm2835SPIClockDivider {
BCM2835_SPI_CLOCK_DIVIDER_65536 = 0,
BCM2835_SPI_CLOCK_DIVIDER_32768 = 32768,
BCM2835_SPI_CLOCK_DIVIDER_16384 = 16384,
BCM2835_SPI_CLOCK_DIVIDER_8192 = 8192,
BCM2835_SPI_CLOCK_DIVIDER_4096 = 4096,
BCM2835_SPI_CLOCK_DIVIDER_2048 = 2048,
BCM2835_SPI_CLOCK_DIVIDER_1024 = 1024,
BCM2835_SPI_CLOCK_DIVIDER_512 = 512,
BCM2835_SPI_CLOCK_DIVIDER_256 = 256,
BCM2835_SPI_CLOCK_DIVIDER_128 = 128,
BCM2835_SPI_CLOCK_DIVIDER_64 = 64,
BCM2835_SPI_CLOCK_DIVIDER_32 = 32,
BCM2835_SPI_CLOCK_DIVIDER_16 = 16,
BCM2835_SPI_CLOCK_DIVIDER_8 = 8,
BCM2835_SPI_CLOCK_DIVIDER_4 = 4,
BCM2835_SPI_CLOCK_DIVIDER_2 = 2,
BCM2835_SPI_CLOCK_DIVIDER_1 = 1
};
Bestie the65536one is0, not65536π that's not a typo on my end, that's literally what it says. Read the numbers, don't vibe-guess them.
enum bcm2835I2CClockDividerβ the divider used to generate the I2C clock from the system clock. Clock divided is based on nominal base clock rate of250MHz. Typedef'd asbcm2835I2CClockDivider.
enum bcm2835I2CClockDivider {
BCM2835_I2C_CLOCK_DIVIDER_2500 = 2500,
BCM2835_I2C_CLOCK_DIVIDER_626 = 626,
BCM2835_I2C_CLOCK_DIVIDER_150 = 150,
BCM2835_I2C_CLOCK_DIVIDER_148 = 148
};
enum bcm2835I2CReasonCodesβ the reason codes for thebcm2835_i2c_writeandbcm2835_i2c_readfunctions. Typedef'd asbcm2835I2CReasonCodes.
enum bcm2835I2CReasonCodes {
BCM2835_I2C_REASON_OK = 0x00,
BCM2835_I2C_REASON_ERROR_NACK = 0x01,
BCM2835_I2C_REASON_ERROR_CLKT = 0x02,
BCM2835_I2C_REASON_ERROR_DATA = 0x04,
BCM2835_I2C_REASON_ERROR_TIMEOUT = 0x08
};
π¦ Variables π¦
These are the library's global girlies β pointers and sizes just hanging out in the open, ready to be read. Note who's volatile and who isn't, that's on purpose π
off_t bcm2835_peripherals_basesize_t bcm2835_peripherals_sizeuint32_t * bcm2835_peripheralsvolatile uint32_t * bcm2835_stvolatile uint32_t * bcm2835_gpiovolatile uint32_t * bcm2835_pwmvolatile uint32_t * bcm2835_clkvolatile uint32_t * bcm2835_padsvolatile uint32_t * bcm2835_spi0volatile uint32_t * bcm2835_bsc0volatile uint32_t * bcm2835_bsc1volatile uint32_t * bcm2835_auxvolatile uint32_t * bcm2835_spi1volatile uint32_t * bcm2835_smi
π Detailed Description π
The values here are designed to be passed to various functions in the bcm2835 library. That's the whole tea β β they're not decoration, they're the actual arguments these functions are expecting, so hand them over exactly as written π«Ά
β¨ Macro Definition Documentation β¨
okay bestie, here's the macro tea β β every single #define in this section, same order, same values, no cap. π
#define BCM2835_AUX_BASE 0x215000β Base Address of the AUX registers. the AUX home base π#define BCM2835_AUX_ENABLE_SPI0 0x02β SPI0 (SPI1 in the device). the naming is a whole situation, bestie β¨#define BCM2835_AUX_ENABLE_SPI1 0x04β SPI1 (SPI2 in the device). yes, another plot twist π¦#define BCM2835_AUX_IRQ 0x0000βxxx. literally justxxx, iconic mystery energy π#define BCM2835_AUX_SPI_CLOCK_MAX 125000000β125Mhz. fast queen π₯#define BCM2835_AUX_SPI_CLOCK_MIN 30500β30,5kHz. comma included, periodt π#define BCM2835_AUX_SPI_CNTL0_CS0_N 0x000C0000β CS 0 low. grounded πΈ#define BCM2835_AUX_SPI_CNTL0_CS1_N 0x000A0000β CS 1 low. also grounded πΈ#define BCM2835_AUX_SPI_CNTL0_CS2_N 0x00060000β CS 2 low. still grounded πΈ#define BCM2835_AUX_SPI_IO 0x0020β Write = TX, read=RX. the duality of SPI π«Ά#define BCM2835_AUX_SPI_PEEK 0x000Cβ Read but do not take from FF. look but don't touch, respect π#define BCM2835_AUX_SPI_TXHOLD 0x0030β Write = TX keep CS, read=RX. hold that CS, bestie π#define BCM2835_BLOCK_SIZE (4*1024)β Size of memory block on RPi. block party π§#define BCM2835_BSC0_BASE 0x205000β Base Address of the BSC0 registers. BSC0 base camp β#define BCM2835_BSC1_BASE 0x804000β Base Address of the BSC1 registers. BSC1 base camp β#define BCM2835_BSC_A 0x000cβ BSC Master Slave Address. address realness π#define BCM2835_BSC_C 0x0000β BSC Master Control. control freak, but make it I2C π#define BCM2835_BSC_C_CLEAR_1 0x00000020β Clear FIFO Clear. clear the FIFO, clear the vibes π§Ή#define BCM2835_BSC_C_CLEAR_2 0x00000010β Clear FIFO Clear. again, but different bit π§Ή#define BCM2835_BSC_C_I2CEN 0x00008000β I2C Enable, 0 = disabled, 1 = enabled. turn it on or off, no in-between π₯#define BCM2835_BSC_C_INTD 0x00000100β Interrupt on DONE. notify me when you're done, bestie π£#define BCM2835_BSC_C_INTR 0x00000400β Interrupt on RX. RX interrupt glow β¨#define BCM2835_BSC_C_INTT 0x00000200β Interrupt on TX. TX interrupt glow β¨#define BCM2835_BSC_C_READ 0x00000001β Read transfer. read mode activated π#define BCM2835_BSC_C_ST 0x00000080β Start transfer, 1 = Start a new transfer. start the transfer, main character energy π#define BCM2835_BSC_CLKT 0x001cβ BSC Master Clock Stretch Timeout. timeout, but clock stretch edition π#define BCM2835_BSC_DEL 0x0018β BSC Master Data Delay. fashionably late data π#define BCM2835_BSC_DIV 0x0014β BSC Master Clock Divider. divide and conquer π§#define BCM2835_BSC_DLEN 0x0008β BSC Master Data Length. length matters π#define BCM2835_BSC_FIFO 0x0010β BSC Master Data FIFO. FIFO is life π¦#define BCM2835_BSC_FIFO_SIZE 16β BSC FIFO size. 16, slay β¨#define BCM2835_BSC_S 0x0004β BSC Master Status. status check π«Ά#define BCM2835_BSC_S_CLKT 0x00000200β Clock stretch timeout. stretch, but make it timeout π#define BCM2835_BSC_S_DONE 0x00000002β Transfer DONE. DONE done, periodt π#define BCM2835_BSC_S_ERR 0x00000100β ACK error. error, we don't love that π#define BCM2835_BSC_S_RXD 0x00000020β RXD FIFO contains data. data detected πΈ#define BCM2835_BSC_S_RXF 0x00000080β RXF FIFO full, 0 = FIFO is not full, 1 = FIFO is full. full or not full, the binary tea β#define BCM2835_BSC_S_RXR 0x00000008β RXR FIFO needs reading (full). read me, I'm full π#define BCM2835_BSC_S_TA 0x00000001β Transfer Active. active transfer, main character π#define BCM2835_BSC_S_TXD 0x00000010β TXD FIFO can accept data. send it π€#define BCM2835_BSC_S_TXE 0x00000040β TXE FIFO full, 0 = FIFO is not full, 1 = FIFO is full. full again, binary bestie β#define BCM2835_BSC_S_TXW 0x00000004β TXW FIFO needs writing (full). write me, I'm full βοΈ#define BCM2835_CLOCK_BASE 0x101000β Base Address of the Clock/timer registers. clock base, tick tock π°οΈ#define BCM2835_CORE_CLK_HZ 250000000β Speed of the core clock core_clk 250 MHz. 250 MHz, fast queen π₯#define BCM2835_GPAFEN0 0x0088β GPIO Pin Async. Falling Edge Detect 0. falling edge, async era π¦#define BCM2835_GPAFEN1 0x008cβ GPIO Pin Async. Falling Edge Detect 1. falling edge, take two π¦#define BCM2835_GPAREN0 0x007cβ GPIO Pin Async. Rising Edge Detect 0. rising edge, async era π#define BCM2835_GPAREN1 0x0080β GPIO Pin Async. Rising Edge Detect 1. rising edge, take two π#define BCM2835_GPCLR0 0x0028β GPIO Pin Output Clear 0. clear it out π§Ή#define BCM2835_GPCLR1 0x002cβ GPIO Pin Output Clear 1. clear it out again π§Ή#define BCM2835_GPEDS0 0x0040β GPIO Pin Event Detect Status 0. event status, very gossip π#define BCM2835_GPEDS1 0x0044β GPIO Pin Event Detect Status 1. event status, part two π#define BCM2835_GPFEN0 0x0058β GPIO Pin Falling Edge Detect Enable 0. falling edge enable π¦#define BCM2835_GPFEN1 0x005cβ GPIO Pin Falling Edge Detect Enable 1. falling edge enable, again π¦#define BCM2835_GPFSEL0 0x0000β GPIO register offsets fromBCM2835_GPIO_BASE. Offsets into the GPIO Peripheral block in bytes per 6.1 Register View GPIO Function Select 0. function select zero, the origin story β¨#define BCM2835_GPFSEL1 0x0004β GPIO Function Select 1. select one π#define BCM2835_GPFSEL2 0x0008β GPIO Function Select 2. select two π#define BCM2835_GPFSEL3 0x000cβ GPIO Function Select 3. select three π#define BCM2835_GPFSEL4 0x0010β GPIO Function Select 4. select four π#define BCM2835_GPFSEL5 0x0014β GPIO Function Select 5. select five, the finale π#define BCM2835_GPHEN0 0x0064β GPIO Pin High Detect Enable 0. high detect, enable β#define BCM2835_GPHEN1 0x0068β GPIO Pin High Detect Enable 1. high detect, enable again β#define BCM2835_GPIO_BASE 0x200000β Base Address of the GPIO registers. GPIO home base π#define BCM2835_GPIO_PADS 0x100000β Base Address of the Pads registers. pads base, cute π#define BCM2835_GPIO_PWM 0x20C000β Base Address of the PWM registers. PWM base, pulse width realness π#define BCM2835_GPLEN0 0x0070β GPIO Pin Low Detect Enable 0. low detect enable π¦#define BCM2835_GPLEN1 0x0074β GPIO Pin Low Detect Enable 1. low detect enable again π¦#define BCM2835_GPLEV0 0x0034β GPIO Pin Level 0. level zero β¨#define BCM2835_GPLEV1 0x0038β GPIO Pin Level 1. level one β¨#define BCM2835_GPPUD 0x0094β GPIO Pin Pull-up/down Enable. pull up or pull down, choose your fighter π#define BCM2835_GPPUDCLK0 0x0098β GPIO Pin Pull-up/down Enable Clock 0. pull clock zero π°οΈ#define BCM2835_GPPUDCLK1 0x009cβ GPIO Pin Pull-up/down Enable Clock 1. pull clock one π°οΈ#define BCM2835_GPREN0 0x004cβ GPIO Pin Rising Edge Detect Enable 0. rising edge enable π#define BCM2835_GPREN1 0x0050β GPIO Pin Rising Edge Detect Enable 1. rising edge enable again π#define BCM2835_GPSET0 0x001cβ GPIO Pin Output Set 0. set it off π₯#define BCM2835_GPSET1 0x0020β GPIO Pin Output Set 1. set it off again π₯#define BCM2835_PAD_DRIVE_10mA 0x04β10mAdrive current. 10mA, strong πͺ#define BCM2835_PAD_DRIVE_12mA 0x05β12mAdrive current. 12mA, stronger πͺ#define BCM2835_PAD_DRIVE_14mA 0x06β14mAdrive current. 14mA, even stronger πͺ#define BCM2835_PAD_DRIVE_16mA 0x07β16mAdrive current. 16mA, maximum slay π#define BCM2835_PAD_DRIVE_2mA 0x00β2mAdrive current. 2mA, soft launch πΈ#define BCM2835_PAD_DRIVE_4mA 0x01β4mAdrive current. 4mA, gentle πΈ#define BCM2835_PAD_DRIVE_6mA 0x02β6mAdrive current. 6mA, warming up πΈ#define BCM2835_PAD_DRIVE_8mA 0x03β8mAdrive current. 8mA, solid πΈ#define BCM2835_PAD_HYSTERESIS_ENABLED 0x08β Hysteresis enabled. hysteresis, enabled era π¦#define BCM2835_PAD_PASSWRD (0x5A << 24)β Pad Control masks Password to enable setting pad mask. password to the pad party π#define BCM2835_PAD_SLEW_RATE_UNLIMITED 0x10β Slew rate unlimited. unlimited slew, no limits π₯#define BCM2835_PADS_GPIO_0_27 0x002cβ Pad control register offsets fromBCM2835_GPIO_PADSPad control register for pads 0 to 27. pads 0 to 27, represented π#define BCM2835_PADS_GPIO_28_45 0x0030β Pad control register for pads 28 to 45. pads 28 to 45, represented π#define BCM2835_PADS_GPIO_46_53 0x0034β Pad control register for pads 46 to 53. pads 46 to 53, represented π#define BCM2835_PAGE_SIZE (4*1024)β Size of memory page on RPi. page size, pageant winner π#define BCM2835_PERI_BASE 0x20000000β Physical addresses for various peripheral register sets Base Physical Address of the BCM 2835 peripheral registers Note this is different for the RPi2 BCM2836, where this is derived from/proc/device-tree/soc/rangesIf/proc/device-tree/soc/rangesexists on a RPi 1 OS, it would be expected to contain the following numbers:Peripherals block base address on RPi 1. the base to rule them all, with lore π#define BCM2835_PERI_SIZE 0x01000000β Size of the peripherals block on RPi 1. big block energy π§±#define BCM2835_RPI2_PERI_BASE 0x3F000000β Alternate base address for RPI 2 / 3. RPI 2 / 3 alternate base, iconic β¨#define BCM2835_RPI4_PERI_BASE 0xFE000000β Alternate base address for RPI 4. RPI 4 alternate base, newer icon β¨#define BCM2835_RPI4_PERI_SIZE 0x01800000β Alternate size for RPI 4. RPI 4 alternate size, big π§±#define BCM2835_SMI_BASE 0x600000β Base address of the SMI registers. SMI base, hello π#define BCM2835_SPI0_BASE 0x204000β Base Address of the SPI0 registers. SPI0 base, the classic π#define BCM2835_SPI0_CLK 0x0008β SPI Master Clock Divider. SPI clock divider, math queen β#define BCM2835_SPI0_CS 0x0000β SPI Master Control and Status. control and status, multitasking π#define BCM2835_SPI0_CS_ADCS 0x00000800β ADCS Automatically Deassert Chip Select. auto deassert, independent π¦#define BCM2835_SPI0_CS_CLEAR 0x00000030β Clear FIFO Clear RX and TX. clear RX and TX, full reset π§Ή#define BCM2835_SPI0_CS_CLEAR_RX 0x00000020β Clear FIFO Clear RX. clear RX only π§Ή#define BCM2835_SPI0_CS_CLEAR_TX 0x00000010β Clear FIFO Clear TX. clear TX only π§Ή#define BCM2835_SPI0_CS_CPHA 0x00000004β Clock Phase. clock phase, phase one π#define BCM2835_SPI0_CS_CPOL 0x00000008β Clock Polarity. clock polarity, polarity queen π#define BCM2835_SPI0_CS_CS 0x00000003β Chip Select. chip select, choose me π#define BCM2835_SPI0_CS_CSPOL 0x00000040β Chip Select Polarity. chip select polarity π¦#define BCM2835_SPI0_CS_CSPOL0 0x00200000β Chip Select 0 Polarity. chip select 0 polarity π¦#define BCM2835_SPI0_CS_CSPOL1 0x00400000β Chip Select 1 Polarity. chip select 1 polarity π¦#define BCM2835_SPI0_CS_CSPOL2 0x00800000β Chip Select 2 Polarity. chip select 2 polarity π¦#define BCM2835_SPI0_CS_DMA_LEN 0x01000000β Enable DMA mode in Lossi mode. DMA mode, lossi mode crossover episode π₯#define BCM2835_SPI0_CS_DMAEN 0x00000100β DMAEN DMA Enable. DMA enable, let's go π#define BCM2835_SPI0_CS_DONE 0x00010000β Done transfer Done. done done, periodt π#define BCM2835_SPI0_CS_INTD 0x00000200β INTD Interrupt on Done. interrupt on done, notify me π£#define BCM2835_SPI0_CS_INTR 0x00000400β INTR Interrupt on RXR. interrupt on RXR π£#define BCM2835_SPI0_CS_LEN 0x00002000β LEN LoSSI enable. LoSSI enable, niche but valid π¦#define BCM2835_SPI0_CS_LEN_LONG 0x02000000β Enable Long data word in Lossi mode if DMA_LEN is set. long data word, only if DMA_LEN is set β conditional queen π#define BCM2835_SPI0_CS_LMONO 0x00004000β Unused. unused, ghosted π#define BCM2835_SPI0_CS_REN 0x00001000β REN Read Enable. read enable, turn up π#define BCM2835_SPI0_CS_RXD 0x00020000β RXD RX FIFO contains Data. RX FIFO has data π₯#define BCM2835_SPI0_CS_RXF 0x00100000β RXF - RX FIFO Full. RX FIFO full, no more room π#define BCM2835_SPI0_CS_RXR 0x00080000β RXR RX FIFO needs Reading (full). RX FIFO needs reading, full situation π#define BCM2835_SPI0_CS_TA 0x00000080β Transfer Active. transfer active, main character π#define BCM2835_SPI0_CS_TE_EN 0x00008000β Unused. unused again, ghosted again π#define BCM2835_SPI0_CS_TXD 0x00040000β TXD TX FIFO can accept Data. TX FIFO can accept data π€#define BCM2835_SPI0_DC 0x0014β SPI DMA DREQ Controls. DMA DREQ controls, fancy β¨#define BCM2835_SPI0_DLEN 0x000cβ SPI Master Data Length. data length, measure twice π#define BCM2835_SPI0_FIFO 0x0004β SPI Master TX and RX FIFOs. TX and RX FIFOs, the duo π«Ά#define BCM2835_SPI0_LTOH 0x0010β SPI LOSSI mode TOH. LOSSI mode TOH, very specific π#define BCM2835_SPI1_BASE 0x215080β Base Address of the AUX_SPI1 registers. AUX_SPI1 base, spin-off π#define BCM2835_SPI2_BASE 0x2150C0β Base Address of the AUX_SPI2 registers. AUX_SPI2 base, sequel π#define BCM2835_ST_BASE 0x3000β Offsets for the bases of various peripherals within the peripherals block / Base Address of the System Timer registers. system timer base, the clock keeper π°οΈ#define BCM2835_ST_CHI 0x0008β System Timer Counter Upper 32 bits. upper 32 bits, high half β¬οΈ#define BCM2835_ST_CLO 0x0004β System Timer Counter Lower 32 bits. lower 32 bits, low half β¬οΈ#define BCM2835_ST_CS 0x0000β System Timer Control/Status. system timer control/status, dual threat π#define BMC2835_RPI2_DT_FILENAME '/proc/device-tree/soc/ranges'β On all recent OSs, the base of the peripherals is read from a /proc file. read from a/procfile, very Unix of it π§#define HIGH 0x1β This means pin HIGH, true, 3.3volts on a pin. HIGH, true, 3.3 volts β turned up β‘#define LOW 0x0β This means pin LOW, false, 0volts on a pin. LOW, false, 0 volts β grounded π#define MIN(a, b) (a < b ? a : b)β Return the minimum of 2 numbers. minimum of 2 numbers, tiny but mighty π§
β¨ Enumeration Type Documentation β¨
okay so enum bcm2835FunctionSelect is giving port function realness β¨
bcm2835PortFunction Port function select modes for bcm2835_gpio_fsel(). π
Enumerator π«Ά
BCM2835_GPIO_FSEL_INPTβ Input0b000. input mode, listening era πBCM2835_GPIO_FSEL_OUTPβ Output0b001. output mode, speaking era π£BCM2835_GPIO_FSEL_ALT0β Alternate function 00b100. alt 0, the original alternate π¦BCM2835_GPIO_FSEL_ALT1β Alternate function 10b101. alt 1, the sequel π¦BCM2835_GPIO_FSEL_ALT2β Alternate function 20b110,. alt 2, comma included, periodt πBCM2835_GPIO_FSEL_ALT3β Alternate function 30b111. alt 3, trilogy energy π¦BCM2835_GPIO_FSEL_ALT4β Alternate function 40b011. alt 4, unexpected but iconic π¦BCM2835_GPIO_FSEL_ALT5β Alternate function 50b010. alt 5, the finale π¦
BCM2835_GPIO_FSEL_MASK β the mask for the function-select bits, and it's 0b111 bestie, three whole bits π
πΈ enum bcm2835I2CClockDivider πΈ
bcm2835I2CClockDivider is the divider situation used to generate the I2C clock from the system clock. The clock divided is based on a nominal base clock rate of 250MHz. Slay. β¨
Enumerator:
BCM2835_I2C_CLOCK_DIVIDER_2500β2500=10us=100 kHzπBCM2835_I2C_CLOCK_DIVIDER_626β622=2.504us=399.3610 kHzBCM2835_I2C_CLOCK_DIVIDER_150β150=60ns=1.666 MHz(this is the default at reset, no cap)BCM2835_I2C_CLOCK_DIVIDER_148β148=59ns=1.689 MHzποΈ
π enum bcm2835I2CReasonCodes π
bcm2835I2CReasonCodes β the reason codes that bcm2835_i2c_write and bcm2835_i2c_read hand you back. It's giving "explain yourself" energy fr fr.
Enumerator:
BCM2835_I2C_REASON_OKβ Success π (the one you actually want)BCM2835_I2C_REASON_ERROR_NACKβ received a NACK πBCM2835_I2C_REASON_ERROR_CLKTβ received Clock Stretch TimeoutBCM2835_I2C_REASON_ERROR_DATAβ not all data is sent / received πBCM2835_I2C_REASON_ERROR_TIMEOUTβ a time out occurred during sending
π¦ enum bcm2835PadGroup π¦
bcm2835PadGroup β the pad group specification for bcm2835_gpio_pad(). Pads got groups now, iconic.
Enumerator:
BCM2835_PAD_GROUP_GPIO_0_27β pad group for GPIO pads0to27BCM2835_PAD_GROUP_GPIO_28_45β pad group for GPIO pads28to45BCM2835_PAD_GROUP_GPIO_46_53β pad group for GPIO pads46to53
π enum bcm2835PUDControl π
bcm2835PUDControl β the pullup/pulldown defines for bcm2835_gpio_pud(). Little binary values, adorable.
Enumerator:
BCM2835_GPIO_PUD_OFFβ Off ? disable pull-up/down0b00(yes, the question mark is canon, I don't make the rules π)BCM2835_GPIO_PUD_DOWNβ enable Pull Down control0b01BCM2835_GPIO_PUD_UPβ enable Pull Up control0b10β¬οΈ
π enum bcm2835RegisterBase π
bcm2835RegisterBase β the register bases you feed to bcm2835_regbase(). Pick your fighter:
Enumerator:
BCM2835_REGBASE_STβ base of the ST (System Timer) registers.BCM2835_REGBASE_GPIOβ base of the GPIO registers.BCM2835_REGBASE_PWMβ base of the PWM registers.BCM2835_REGBASE_CLKβ base of the CLK registers.BCM2835_REGBASE_PADSβ base of the PADS registers.BCM2835_REGBASE_SPI0β base of the SPI0 registers.BCM2835_REGBASE_BSC0β base of the BSC0 registers.BCM2835_REGBASE_BSC1β base of the BSC1 registers.BCM2835_REGBASE_AUXβ base of the AUX registers.BCM2835_REGBASE_SPI1β base of the SPI1 registers.BCM2835_REGBASE_SMIβ base of the SMI registers.
β enum bcm2835SPIBitOrder β
bcm2835SPIBitOrder β SPI bit order. Specifies the SPI data bit ordering for bcm2835_spi_setBitOrder(). Which end of the bits goes first, basically.
Enumerator:
BCM2835_SPI_BIT_ORDER_LSBFIRSTβ LSB FirstBCM2835_SPI_BIT_ORDER_MSBFIRSTβ MSB First π
π enum bcm2835SPIChipSelect π
bcm2835SPIChipSelect β specify the SPI chip select pin(s). Choose your chip bestie.
Enumerator:
BCM2835_SPI_CS0β Chip Select 0BCM2835_SPI_CS1β Chip Select 1BCM2835_SPI_CS2β Chip Select 2 (ie pinsCS1andCS2are asserted) πBCM2835_SPI_CS_NONEβ no CS, control it yourself. Main character move, honestly. π«Ά
π₯ enum bcm2835SPIClockDivider π₯
bcm2835SPIClockDivider β the divider used to generate the SPI clock from the system clock. The figures below give the divider, clock period and clock frequency. Clock divided is based on a nominal core clock rate of 250MHz on RPi1 and RPi2, and 400MHz on RPi3.
It is reported that (contrary to the documentation) any even divider may be used. π«£
The frequencies shown for each divider have been confirmed by measurement on RPi1 and RPi2. The system clock frequency on RPi3 is different, so the frequency you get from a given divider will be different. See comments in 'SPI Pins' for information about reliable SPI speeds.
Note: it is possible to change the core clock rate of the RPi 3 back to 250MHz, by putting
core_freq=250
in the config.txt β¨
Enumerator:
BCM2835_SPI_CLOCK_DIVIDER_65536β65536=3.814697260kHzon Rpi2,6.1035156kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_32768β32768=7.629394531kHzon Rpi2,12.20703125kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_16384β16384=15.25878906kHzon Rpi2,24.4140625kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_8192β8192=30.51757813kHzon Rpi2,48.828125kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_4096β4096=61.03515625kHzon Rpi2,97.65625kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_2048β2048=122.0703125kHzon Rpi2,195.3125kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_1024β1024=244.140625kHzon Rpi2,390.625kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_512β512=488.28125kHzon Rpi2,781.25kHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_256β256=976.5625kHzon Rpi2,1.5625MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_128β128=1.953125MHzon Rpi2,3.125MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_64β64=3.90625MHzon Rpi2,6.250MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_32β32=7.8125MHzon Rpi2,12.5MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_16β16=15.625MHzon Rpi2,25MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_8β8=31.25MHzon Rpi2,50MHzon RPI3BCM2835_SPI_CLOCK_DIVIDER_4β4=62.5MHzon Rpi2,100MHzon RPI3. Dont expect this speed to work reliably. πBCM2835_SPI_CLOCK_DIVIDER_2β2=125MHzon Rpi2,200MHzon RPI3, fastest you can get. Dont expect this speed to work reliably. ππBCM2835_SPI_CLOCK_DIVIDER_1β1=3.814697260kHzon Rpi2,6.1035156kHzon RPI3, same as0/65536
π§ enum bcm2835SPIMode π§
SPI Data mode β specify the SPI data mode to be passed to bcm2835_spi_setDataMode(). CPOL and CPHA, the iconic duo.
Enumerator:
BCM2835_SPI_MODE0βCPOL = 0,CPHA = 0BCM2835_SPI_MODE1βCPOL = 0,CPHA = 1BCM2835_SPI_MODE2βCPOL = 1,CPHA = 0BCM2835_SPI_MODE3βCPOL = 1,CPHA = 1
π enum RPiGPIOPin π
GPIO Pin Numbers, bestie. Here we define Raspberry Pin GPIO pins on P1 in terms of the underlying BCM GPIO pin numbers. These can be passed as a pin number to any function requiring a pin.
Not all pins on the RPi 26 bin IDE plug are connected to GPIO pins and some can adopt an alternate function. RPi version 2 has some slightly different pinouts, and these are valuesRPI_V2_*. RPi B+ has yet differnet pinouts and these are defined inRPI_BPLUS_*. β οΈ
At bootup, pins 8 and 10 are set to UART0_TXD, UART0_RXD (ie the alt0 function) respectively. When SPI0 is in use (ie after bcm2835_spi_begin()), SPI0 pins are dedicated to SPI and cant be controlled independently.
If you are using the RPi Compute Module, just use the GPIO number: there is no need to use one of these symbolic names. π«Ά
Enumerator:
RPI_GPIO_P1_03β Version 1, Pin P1-03RPI_GPIO_P1_05β Version 1, Pin P1-05RPI_GPIO_P1_07β Version 1, Pin P1-07RPI_GPIO_P1_08β Version 1, Pin P1-08, defaults to alt function 0UART0_TXDRPI_GPIO_P1_10β Version 1, Pin P1-10, defaults to alt function 0UART0_RXDRPI_GPIO_P1_11β Version 1, Pin P1-11RPI_GPIO_P1_12β Version 1, Pin P1-12, can be PWM channel 0 inALT FUN 5RPI_GPIO_P1_13β Version 1, Pin P1-13RPI_GPIO_P1_15β Version 1, Pin P1-15RPI_GPIO_P1_16β Version 1, Pin P1-16RPI_GPIO_P1_18β Version 1, Pin P1-18RPI_GPIO_P1_19β Version 1, Pin P1-19,MOSIwhen SPI0 in useRPI_GPIO_P1_21β Version 1, Pin P1-21,MISOwhen SPI0 in useRPI_GPIO_P1_22β Version 1, Pin P1-22RPI_GPIO_P1_23β Version 1, Pin P1-23,CLKwhen SPI0 in useRPI_GPIO_P1_24β Version 1, Pin P1-24,CE0when SPI0 in useRPI_GPIO_P1_26β Version 1, Pin P1-26,CE1when SPI0 in useRPI_V2_GPIO_P1_03β Version 2, Pin P1-03RPI_V2_GPIO_P1_05β Version 2, Pin P1-05RPI_V2_GPIO_P1_07β Version 2, Pin P1-07RPI_V2_GPIO_P1_08β Version 2, Pin P1-08, defaults to alt function 0UART0_TXDRPI_V2_GPIO_P1_10β Version 2, Pin P1-10, defaults to alt function 0UART0_RXDRPI_V2_GPIO_P1_11β Version 2, Pin P1-11RPI_V2_GPIO_P1_12β Version 2, Pin P1-12, can be PWM channel 0 inALT FUN 5RPI_V2_GPIO_P1_13β Version 2, Pin P1-13RPI_V2_GPIO_P1_15β Version 2, Pin P1-15RPI_V2_GPIO_P1_16β Version 2, Pin P1-16RPI_V2_GPIO_P1_18β Version 2, Pin P1-18RPI_V2_GPIO_P1_19β Version 2, Pin P1-19,MOSIwhen SPI0 in useRPI_V2_GPIO_P1_21β Version 2, Pin P1-21,MISOwhen SPI0 in useRPI_V2_GPIO_P1_22β Version 2, Pin P1-22RPI_V2_GPIO_P1_23β Version 2, Pin P1-23,CLKwhen SPI0 in useRPI_V2_GPIO_P1_24β Version 2, Pin P1-24,CE0when SPI0 in useRPI_V2_GPIO_P1_26β Version 2, Pin P1-26,CE1when SPI0 in useRPI_V2_GPIO_P1_29β Version 2, Pin P1-29RPI_V2_GPIO_P1_31β Version 2, Pin P1-31RPI_V2_GPIO_P1_32β Version 2, Pin P1-32RPI_V2_GPIO_P1_33β Version 2, Pin P1-33RPI_V2_GPIO_P1_35β Version 2, Pin P1-35, can be PWM channel 1 inALT FUN 5RPI_V2_GPIO_P1_36β Version 2, Pin P1-36RPI_V2_GPIO_P1_37β Version 2, Pin P1-37RPI_V2_GPIO_P1_38β Version 2, Pin P1-38RPI_V2_GPIO_P1_40β Version 2, Pin P1-40RPI_V2_GPIO_P5_03β Version 2, Pin P5-03RPI_V2_GPIO_P5_04β Version 2, Pin P5-04RPI_V2_GPIO_P5_05β Version 2, Pin P5-05RPI_V2_GPIO_P5_06β Version 2, Pin P5-06RPI_BPLUS_GPIO_J8_03β B+, Pin J8-03RPI_BPLUS_GPIO_J8_05β B+, Pin J8-05RPI_BPLUS_GPIO_J8_07β B+, Pin J8-07RPI_BPLUS_GPIO_J8_08β B+, Pin J8-08, defaults to alt function 0UART0_TXDRPI_BPLUS_GPIO_J8_10β B+, Pin J8-10, defaults to alt function 0UART0_RXDRPI_BPLUS_GPIO_J8_11β B+, Pin J8-11RPI_BPLUS_GPIO_J8_12β B+, Pin J8-12, can be PWM channel 0 inALT FUN 5RPI_BPLUS_GPIO_J8_13β B+, Pin J8-13RPI_BPLUS_GPIO_J8_15β B+, Pin J8-15RPI_BPLUS_GPIO_J8_16β B+, Pin J8-16RPI_BPLUS_GPIO_J8_18β B+, Pin J8-18RPI_BPLUS_GPIO_J8_19β B+, Pin J8-19,MOSIwhen SPI0 in useRPI_BPLUS_GPIO_J8_21β B+, Pin J8-21,MISOwhen SPI0 in useRPI_BPLUS_GPIO_J8_22β B+, Pin J8-22RPI_BPLUS_GPIO_J8_23β B+, Pin J8-23,CLKwhen SPI0 in useRPI_BPLUS_GPIO_J8_24β B+, Pin J8-24,CE0when SPI0 in useRPI_BPLUS_GPIO_J8_26β B+, Pin J8-26,CE1when SPI0 in useRPI_BPLUS_GPIO_J8_29β B+, Pin J8-29,RPI_BPLUS_GPIO_J8_31β B+, Pin J8-31RPI_BPLUS_GPIO_J8_32β B+, Pin J8-32RPI_BPLUS_GPIO_J8_33β B+, Pin J8-33RPI_BPLUS_GPIO_J8_35β B+, Pin J8-35, and fun fact: this one can be PWM channel 1 in ALT FUN 5 πRPI_BPLUS_GPIO_J8_36β B+, Pin J8-36RPI_BPLUS_GPIO_J8_37β B+, Pin J8-37RPI_BPLUS_GPIO_J8_38β B+, Pin J8-38RPI_BPLUS_GPIO_J8_40β B+, Pin J8-40
π«Ά Variable Documentation π«Ά
okay bestie, this is the part where we meet the actual global variables β¨ these are the [extern] legends you get to poke at from your own code. Let's go, one by one π
volatile uint32_t* bcm2835_aux [extern]
Base of the AUX registers. This one only shows up after bcm2835_init has been called β as root, no cap π
volatile uint32_t* bcm2835_bsc0 [extern]
Base of the BSC0 registers. Available after bcm2835_init has been called (as root) π
volatile uint32_t* bcm2835_bsc1 [extern]
Base of the BSC1 registers. Available after bcm2835_init has been called (as root) π
volatile uint32_t* bcm2835_clk [extern]
Base of the CLK registers. Available after bcm2835_init has been called (as root) β°
volatile uint32_t* bcm2835_gpio [extern]
Base of the GPIO registers. Available after bcm2835_init has been called. (no root energy required on this one, bestie β she's the chill one) πΈ
volatile uint32_t* bcm2835_pads [extern]
Base of the PADS registers. Available after bcm2835_init has been called (as root) π
uint32_t* bcm2835_peripherals [extern]
The virtual memory address of the mapped peripherals block. Virtual, not physical β she lives in your process's little dream world π
off_t bcm2835_peripherals_base [extern]
Physical address and size of the peripherals block. May be overridden on RPi2 β so don't you dare hardcode her fr fr π
size_t bcm2835_peripherals_size [extern]
Size of the peripherals block that's gonna get mapped π
volatile uint32_t* bcm2835_pwm [extern]
Base of the PWM registers. Available after bcm2835_init has been called (as root) π
volatile uint32_t* bcm2835_smi [extern]
Base of SMI registers. Available after bcm2835_init has been called (as root) β¨
volatile uint32_t* bcm2835_spi0 [extern]
Base of the SPI0 registers. Available after bcm2835_init has been called (as root) π¦
volatile uint32_t* bcm2835_spi1 [extern]
Base of the SPI1 registers. Available after bcm2835_init has been called (as root) π¦
volatile uint32_t* bcm2835_st [extern]
Base of the ST (System Timer) registers. Available after bcm2835_init has been called (as root) β±οΈ
ngl the pattern here is so satisfying β nearly all of these are just "callbcm2835_initas root first, then she's yours" πbcm2835_gpiois the icon who skips the root requirement, andbcm2835_peripherals,bcm2835_peripherals_baseandbcm2835_peripherals_sizeare doing their own whole thing π«Ά
π Author π
Generated automatically by Doxygen for bcm2835 straight from the source code. Not a human wrote this, bestie β the robot did it and honestly she ate π β¨
aaaand that's the whole page, you made it to the end!! π this was bcm2835, Version 1.75, and you've been reading constants(3). go forth and poke at registers responsibly, ily, bye bestie ππ¦π
π¦ where this page comes from
- debian trixie: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu noble: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu questing: libbcm2835-dev 1.75+ds-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms