Skip to content

Commit eadc2f5

Browse files
tinnedkarmaxiaoxiang781216
authored andcommitted
feat: add basic driver for amg88xx sensor
Basic amg88xx sensor handling (open, close, read, ioctl). No interrupts supported. I intend to add support for this feature when I gain more know-how on nuttx/posix.
1 parent 882c0d0 commit eadc2f5

File tree

10 files changed

+1040
-0
lines changed

10 files changed

+1040
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/****************************************************************************
2+
* boards/arm/stm32/common/include/stm32_amg88xx.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H
22+
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <nuttx/config.h>
29+
30+
/****************************************************************************
31+
* Pre-processor Definitions
32+
****************************************************************************/
33+
34+
/****************************************************************************
35+
* Public Types
36+
****************************************************************************/
37+
38+
/****************************************************************************
39+
* Public Data
40+
****************************************************************************/
41+
42+
#ifdef __cplusplus
43+
#define EXTERN extern "C"
44+
extern "C"
45+
{
46+
#else
47+
#define EXTERN extern
48+
#endif
49+
50+
/****************************************************************************
51+
* Inline Functions
52+
****************************************************************************/
53+
54+
/****************************************************************************
55+
* Public Function Prototypes
56+
****************************************************************************/
57+
58+
/****************************************************************************
59+
* Name: board_amg88xx_initialize()
60+
*
61+
* Description:
62+
* Initialize and register the AMG88xx infrared matrix sensor driver.
63+
*
64+
* Input Parameters:
65+
* busno - The I2C bus number
66+
*
67+
* Returned Value:
68+
* Zero (OK) on success; a negated errno value on failure.
69+
*
70+
****************************************************************************/
71+
72+
int board_amg88xx_initialize(int busno);
73+
74+
#undef EXTERN
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
79+
#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H */

boards/arm/stm32/common/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ if(CONFIG_CL_MFRC522)
128128
list(APPEND SRCS stm32_mfrc522.c)
129129
endif()
130130

131+
if(CONFIG_SENSORS_AMG88XX)
132+
list(APPEND SRCS stm32_amg88xx.c)
133+
endif()
134+
131135
if(CONFIG_LIS3DSH)
132136
list(APPEND SRCS stm32_lis3dsh.c)
133137
endif()

boards/arm/stm32/common/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ ifeq ($(CONFIG_CL_MFRC522),y)
136136
CSRCS += stm32_mfrc522.c
137137
endif
138138

139+
ifeq ($(CONFIG_SENSORS_AMG88XX),y)
140+
CSRCS+= stm32_amg88xx.c
141+
endif
142+
139143
ifeq ($(CONFIG_LIS3DSH),y)
140144
CSRCS += stm32_lis3dsh.c
141145
endif
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/****************************************************************************
2+
* boards/arm/stm32/common/src/stm32_amg88xx.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <nuttx/config.h>
26+
27+
#include <errno.h>
28+
#include <debug.h>
29+
30+
#include <nuttx/i2c/i2c_master.h>
31+
#include <nuttx/sensors/amg88xx.h>
32+
#include <arch/board/board.h>
33+
34+
#include "stm32.h"
35+
#include "stm32_i2c.h"
36+
37+
/****************************************************************************
38+
* Pre-processor Definitions
39+
****************************************************************************/
40+
41+
/* What is the point of passing devno if only
42+
* a single config struct is defined
43+
* irm = infrared map / infrared matrix
44+
*/
45+
46+
#define AMG88XX_DEVNO_PATH_0 "/dev/irm0"
47+
48+
/****************************************************************************
49+
* Private Function Prototypes
50+
****************************************************************************/
51+
52+
/****************************************************************************
53+
* Private Data
54+
****************************************************************************/
55+
56+
/* One sensor connected to the board */
57+
58+
/* During device registration OS allocates an pointer to an amg88xx_config_s
59+
* not the actual struct, that implies that for each sensor there is the
60+
* need for a config struct at a valid memory location which will be passed
61+
* to the pointer mentioned above. So there can be only one sensor,
62+
* as there is one global config struct instantiated here.
63+
* Is this the intended behaviour to minimize the memory allocated through
64+
* malloc?
65+
*/
66+
67+
static struct amg88xx_config_s g_amg88xx_config_0 =
68+
{
69+
.addr = CONFIG_SENSOR_AMG88XX_ADDR,
70+
.speed = I2C_SPEED_STANDARD
71+
};
72+
73+
/****************************************************************************
74+
* Private Functions
75+
****************************************************************************/
76+
77+
/****************************************************************************
78+
* Public Functions
79+
****************************************************************************/
80+
81+
/****************************************************************************
82+
* Name: board_amg88xx_initialize()
83+
*
84+
* Description:
85+
* Initialize and register the AMG88xx infrared matrix sensor driver.
86+
*
87+
* Input Parameters:
88+
* busno - The I2C bus number
89+
*
90+
* Returned Value:
91+
* Zero (OK) on success; a negated errno value on failure.
92+
*
93+
****************************************************************************/
94+
95+
int board_amg88xx_initialize(int busno)
96+
{
97+
struct i2c_master_s *i2c;
98+
int ret;
99+
100+
sninfo("Initializing AMG88xx!\n");
101+
102+
/* Initialize I2C */
103+
104+
i2c = stm32_i2cbus_initialize(busno);
105+
106+
if (!i2c)
107+
{
108+
return -ENODEV;
109+
}
110+
111+
/* Then register the sensor */
112+
113+
ret = amg88xx_register(AMG88XX_DEVNO_PATH_0, i2c, &g_amg88xx_config_0);
114+
if (ret < 0)
115+
{
116+
syslog(LOG_ERR, "ERROR: Error registering AMG88xx\n");
117+
}
118+
119+
return ret;
120+
}

boards/arm/stm32/nucleo-f429zi/src/stm32_appinitialize.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,50 @@
3535
#include "stm32_romfs.h"
3636
#endif
3737

38+
#ifdef CONFIG_SENSORS_AMG88XX
39+
#include "stm32_amg88xx.h"
40+
#endif
41+
42+
#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
43+
# include "stm32_i2c.h"
44+
#endif
45+
46+
/****************************************************************************
47+
* Private Functions
48+
****************************************************************************/
49+
50+
/****************************************************************************
51+
* Name: stm32_i2c_register
52+
*
53+
* Description:
54+
* Register one I2C drivers for the I2C tool.
55+
*
56+
****************************************************************************/
57+
58+
#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
59+
static void stm32_i2c_register(int bus)
60+
{
61+
struct i2c_master_s *i2c;
62+
int ret;
63+
64+
i2c = stm32_i2cbus_initialize(bus);
65+
if (i2c == NULL)
66+
{
67+
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
68+
}
69+
else
70+
{
71+
ret = i2c_register(i2c, bus);
72+
if (ret < 0)
73+
{
74+
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
75+
bus, ret);
76+
stm32_i2cbus_uninitialize(i2c);
77+
}
78+
}
79+
}
80+
#endif
81+
3882
/****************************************************************************
3983
* Public Functions
4084
****************************************************************************/
@@ -167,6 +211,14 @@ int board_app_initialize(uintptr_t arg)
167211
}
168212
#endif
169213

214+
#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
215+
stm32_i2c_register(1);
216+
#endif
217+
218+
#ifdef CONFIG_SENSORS_AMG88XX
219+
board_amg88xx_initialize(1);
220+
#endif
221+
170222
UNUSED(ret);
171223
return OK;
172224
}

drivers/sensors/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ if(CONFIG_SENSORS)
284284
list(APPEND SRCS bmm150_uorb.c)
285285
endif()
286286

287+
if(CONFIG_SENSORS_AMG88XX)
288+
list(APPEND SRCS amg88xx.c)
289+
endif()
290+
287291
endif() # CONFIG_I2C
288292

289293
# These drivers depend on SPI support

drivers/sensors/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,4 +1717,36 @@ config SENSORS_LTR308_THREAD_STACKSIZE
17171717

17181718
endif # SENSORS_LTR308
17191719

1720+
config SENSORS_AMG88XX
1721+
bool "AMG88xx infrared array sensor"
1722+
default n
1723+
select I2C
1724+
---help---
1725+
Enable driver support for AMG88xx infrared array sensor.
1726+
1727+
if SENSORS_AMG88XX
1728+
1729+
choice
1730+
prompt "AMG88xx AD_SELECT value"
1731+
default SENSOR_AMG88XX_AD_SELECT_0
1732+
---help---
1733+
AD SELECT sets the amg88xx i2c address
1734+
AD_SELECT tied to GND -> sensor address 0x68
1735+
AD_SELECT tied to VCC -> sensor address 0x69
1736+
1737+
config SENSOR_AMG88XX_AD_SELECT_0
1738+
bool "AD_SELECT tied to GND"
1739+
1740+
config SENSOR_AMG88XX_AD_SELECT_1
1741+
bool "AD_SELECT tied to VCC"
1742+
1743+
endchoice
1744+
1745+
config SENSOR_AMG88XX_ADDR
1746+
hex
1747+
default 0x68 if SENSOR_AMG88XX_AD_SELECT_0
1748+
default 0x69 if SENSOR_AMG88XX_AD_SELECT_1
1749+
1750+
endif # SENSORS_AMG88XX
1751+
17201752
endif # SENSORS

0 commit comments

Comments
 (0)