Skip to content

Commit e197ec0

Browse files
Kerogitcederom
authored andcommitted
boards/avr/avrdx/breadxavr: add TC74Ax thermal sensor to the board
This patch adds the option to connect TC74Ax thermal sensor to AVR Dx chip connected to a breadboard for development purposes. If enabled - which can only be done with I2C support and the driver enabled - it registers sensor's driver for use. Signed-off-by: Kerogit <[email protected]>
1 parent 07cbb4f commit e197ec0

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

Documentation/platforms/avr/avrdx/boards/breadxavr/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ expectation that requires pressed button to read as logical 1 and depressed
6363
button as logical 0 while allowing the board to operate without external
6464
components (internal pull-ups are used.)
6565

66+
I\ :sup:`2`\ C temperature sensor TC74Ax
67+
----------------------------------------
68+
69+
The board has readymade configuration for TC74Ax temperature sensor
70+
from Microchip.
71+
72+
To enable it, it is needed to:
73+
74+
- enable :menuselection:`Device Drivers --> I2C Driver Support`
75+
- enable :menuselection:`System Type --> AVR DA/DB Peripheral Selections --> Enable TWI (I2C) driver for interface 0`
76+
- enable :menuselection:`Device Drivers --> Sensor Device Support --> Microchip TC74Ax Digital Thermal Sensor`
77+
- configure the driver for requested mode of operation with regards
78+
to multimaster and power management
79+
- enable :menuselection:`Board Selection --> Enable initializing I2C TC74Ax sensor`
80+
- configure variant of the connected sensor
81+
82+
The sensor is made available as ``/dev/tc74ax``. Further information regarding usage of the sensor is available in its driver's documentation: :doc:`/components/drivers/special/sensors/tc74ax`
83+
6684
Compile & Flash
6785
===============
6886

boards/avr/avrdx/breadxavr/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,26 @@ config BREADXAVR_BUTTONS_DRIVER
1313
If set, button driver registered as /dev/buttons
1414
for PORT A and PORT C (pins 2 and 3 for both ports.)
1515

16+
config BREADXAVR_TC74AX_SENSOR
17+
bool "Enable initializing I2C TC74Ax sensor"
18+
depends on AVR_TWI0 && SENSORS_TC74AX
19+
select BOARD_LATE_INITIALIZE
20+
default n
21+
---help---
22+
If set, the board will register driver for Microchip TC74Ax
23+
thermal sensor.
24+
25+
if BREADXAVR_TC74AX_SENSOR
26+
27+
config BREADXAVR_TC74AX_SENSOR_VARIANT
28+
int "TC74Ax variant"
29+
default 0
30+
range 0 7
31+
---help---
32+
Select specific part used on your (bread)board. Number chosen
33+
here corresponds to the "x" in the part name (and also to I2C
34+
address of the sensor.)
35+
36+
endif
37+
1638
endif

boards/avr/avrdx/breadxavr/src/avrdx_init.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
# include <nuttx/input/buttons.h>
3333
#endif
3434

35+
#ifdef CONFIG_BREADXAVR_TC74AX_SENSOR
36+
# include <nuttx/sensors/tc74ax.h>
37+
#endif
38+
3539
#include <assert.h>
3640
#include <avr/io.h>
3741

3842
#include "avrdx_gpio.h"
43+
#include "avrdx_twi.h"
3944

4045
/****************************************************************************
4146
* Pre-processor Definitions
@@ -92,3 +97,49 @@ void board_early_initialize(void)
9297
}
9398

9499
#endif /* CONFIG_BOARD_EARLY_INITIALIZE */
100+
101+
/****************************************************************************
102+
* Name: board_late_initialize
103+
*
104+
* Description:
105+
* Function called by the OS when BOARD_LATE_INITIALIZE is set.
106+
* Called after up_initialize, OS has been initialized at this point
107+
* and it is okay to initialize drivers. Running in special kernel
108+
* thread so waiting is allowed. Executed just before application code.
109+
*
110+
****************************************************************************/
111+
112+
#ifdef CONFIG_BOARD_LATE_INITIALIZE
113+
void board_late_initialize(void)
114+
{
115+
# ifdef CONFIG_BREADXAVR_TC74AX_SENSOR
116+
FAR struct i2c_master_s *i2c;
117+
# endif
118+
int ret = OK;
119+
120+
# ifdef CONFIG_BREADXAVR_TC74AX_SENSOR
121+
122+
# if (CONFIG_BREADXAVR_TC74AX_SENSOR_VARIANT < 0) || \
123+
(CONFIG_BREADXAVR_TC74AX_SENSOR_VARIANT > 7)
124+
# error Incorrect setting of variant, Kconfig should not allow this
125+
# endif
126+
127+
i2c = avrdx_initialize_twi(0);
128+
if (i2c)
129+
{
130+
ret = tc74ax_register("/dev/tc74ax",
131+
i2c,
132+
72 + CONFIG_BREADXAVR_TC74AX_SENSOR_VARIANT);
133+
if (ret != OK)
134+
{
135+
PANIC();
136+
}
137+
}
138+
else {
139+
PANIC();
140+
}
141+
142+
# endif /* ifdef CONFIG_BREADXAVR_TC74AX_SENSOR */
143+
}
144+
145+
#endif /* CONFIG_BOARD_LATE_INITIALIZE */

0 commit comments

Comments
 (0)