Skip to content

Commit a9c7599

Browse files
committed
make PSPI address and speed changeable from outside of header file
1 parent db73e4e commit a9c7599

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/MCP3x6x.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,26 @@
4141
#define MCP_CH1 (0x18) //!< corresponding mux setting
4242
#define MCP_CH0 (0x08) //!< corresponding mux setting
4343

44-
#define MCP3461_DEVICE_TYPE (0x0008) //!< MCP3461 device ID
45-
#define MCP3462_DEVICE_TYPE (0x0009) //!< MCP3462 device ID
46-
#define MCP3464_DEVICE_TYPE (0x000B) //!< MCP3464 device ID
47-
#define MCP3561_DEVICE_TYPE (0x000C) //!< MCP3561 device ID
48-
#define MCP3562_DEVICE_TYPE (0x000D) //!< MCP3562 device ID
49-
#define MCP3564_DEVICE_TYPE (0x000F) //!< MCP3564 device ID
50-
#define MCP3x6x_DEVICE_ADDRESS (0x01) //!< todo
44+
#define MCP3461_DEVICE_TYPE (0x0008) //!< MCP3461 device ID
45+
#define MCP3462_DEVICE_TYPE (0x0009) //!< MCP3462 device ID
46+
#define MCP3464_DEVICE_TYPE (0x000B) //!< MCP3464 device ID
47+
#define MCP3561_DEVICE_TYPE (0x000C) //!< MCP3561 device ID
48+
#define MCP3562_DEVICE_TYPE (0x000D) //!< MCP3562 device ID
49+
#define MCP3564_DEVICE_TYPE (0x000F) //!< MCP3564 device ID
50+
51+
#ifndef MCP3x6x_DEVICE_ADDRESS
52+
# define MCP3x6x_DEVICE_ADDRESS (0x01) //!< DEVICE ADDRESS
53+
#endif
54+
#ifndef MCP3x6x_SPI_SPEED
55+
# define MCP3x6x_SPI_SPEED (20000000) //!< SPI SPEED Value
56+
#endif
57+
#if MCP3x6x_SPI_SPEED > 20000000
58+
# error "MCP3x6x_SPI_SPEED above limit (20MHz)!"
59+
#endif
5160

5261
#define MCP3x6x_SPI_ORDER MSBFIRST //!< SPI ORDER
5362
#define MCP3x6x_SPI_MODE SPI_MODE0 //!< SPI MODE
5463
#define MCP3x6x_SPI_ADR (MCP3x6x_DEVICE_ADDRESS << 6) //!< SPI ADDRESS
55-
#define MCP3x6x_SPI_SPEED (200000) //!< SPI SPEED Value
5664

5765
#define MCP3x6x_CMD_CONVERSION (MCP3x6x_SPI_ADR | 0b101000) //!< fast command
5866
#define MCP3x6x_CMD_STANDBY (MCP3x6x_SPI_ADR | 0b101100) //!< fast command

0 commit comments

Comments
 (0)