Skip to content

Commit

Permalink
feat: add basic driver for amg88xx sensor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LuchianMihai committed Sep 2, 2024
1 parent 63ed723 commit d444ad4
Show file tree
Hide file tree
Showing 10 changed files with 1,040 additions and 0 deletions.
79 changes: 79 additions & 0 deletions boards/arm/stm32/common/include/stm32_amg88xx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/****************************************************************************
* boards/arm/stm32/common/include/stm32_amg88xx.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/****************************************************************************
* Public Types
****************************************************************************/

/****************************************************************************
* Public Data
****************************************************************************/

#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif

/****************************************************************************
* Inline Functions
****************************************************************************/

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

/****************************************************************************
* Name: board_amg88xx_initialize()
*
* Description:
* Initialize and register the AMG88xx infrared matrix sensor driver.
*
* Input Parameters:
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/

int board_amg88xx_initialize(int busno);

#undef EXTERN
#ifdef __cplusplus
}
#endif

#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_AMG88XX_H */
4 changes: 4 additions & 0 deletions boards/arm/stm32/common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ if(CONFIG_CL_MFRC522)
list(APPEND SRCS stm32_mfrc522.c)
endif()

if(CONFIG_SENSORS_AMG88XX)
list(APPEND SRCS stm32_amg88xx.c)
endif()

if(CONFIG_LIS3DSH)
list(APPEND SRCS stm32_lis3dsh.c)
endif()
Expand Down
4 changes: 4 additions & 0 deletions boards/arm/stm32/common/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ ifeq ($(CONFIG_CL_MFRC522),y)
CSRCS += stm32_mfrc522.c
endif

ifeq ($(CONFIG_SENSORS_AMG88XX),y)
CSRCS+= stm32_amg88xx.c
endif

ifeq ($(CONFIG_LIS3DSH),y)
CSRCS += stm32_lis3dsh.c
endif
Expand Down
120 changes: 120 additions & 0 deletions boards/arm/stm32/common/src/stm32_amg88xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/****************************************************************************
* boards/arm/stm32/common/src/stm32_amg88xx.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <errno.h>
#include <debug.h>

#include <nuttx/i2c/i2c_master.h>
#include <nuttx/sensors/amg88xx.h>
#include <arch/board/board.h>

#include "stm32.h"
#include "stm32_i2c.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

/* What is the point of passing devno if only
* a single config struct is defined
* irm = infrared map / infrared matrix
*/

#define AMG88XX_DEVNO_PATH_0 "/dev/irm0"

/****************************************************************************
* Private Function Prototypes
****************************************************************************/

/****************************************************************************
* Private Data
****************************************************************************/

/* One sensor connected to the board */

/* During device registration OS allocates an pointer to an amg88xx_config_s
* not the actual struct, that implies that for each sensor there is the
* need for a config struct at a valid memory location which will be passed
* to the pointer mentioned above. So there can be only one sensor,
* as there is one global config struct instantiated here.
* Is this the intended behaviour to minimize the memory allocated through
* malloc?
*/

static struct amg88xx_config_s g_amg88xx_config_0 =
{
.addr = CONFIG_SENSOR_AMG88XX_ADDR,
.speed = I2C_SPEED_STANDARD
};

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: board_amg88xx_initialize()
*
* Description:
* Initialize and register the AMG88xx infrared matrix sensor driver.
*
* Input Parameters:
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/

int board_amg88xx_initialize(int busno)
{
struct i2c_master_s *i2c;
int ret;

sninfo("Initializing AMG88xx!\n");

/* Initialize I2C */

i2c = stm32_i2cbus_initialize(busno);

if (!i2c)
{
return -ENODEV;
}

/* Then register the sensor */

ret = amg88xx_register(AMG88XX_DEVNO_PATH_0, i2c, &g_amg88xx_config_0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Error registering AMG88xx\n");
}

return ret;
}
52 changes: 52 additions & 0 deletions boards/arm/stm32/nucleo-f429zi/src/stm32_appinitialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@
#include "stm32_romfs.h"
#endif

#ifdef CONFIG_SENSORS_AMG88XX
#include "stm32_amg88xx.h"
#endif

#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
# include "stm32_i2c.h"
#endif

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: stm32_i2c_register
*
* Description:
* Register one I2C drivers for the I2C tool.
*
****************************************************************************/

#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
static void stm32_i2c_register(int bus)
{
struct i2c_master_s *i2c;
int ret;

i2c = stm32_i2cbus_initialize(bus);
if (i2c == NULL)
{
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
}
else
{
ret = i2c_register(i2c, bus);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
bus, ret);
stm32_i2cbus_uninitialize(i2c);
}
}
}
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -167,6 +211,14 @@ int board_app_initialize(uintptr_t arg)
}
#endif

#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
stm32_i2c_register(1);
#endif

#ifdef CONFIG_SENSORS_AMG88XX
board_amg88xx_initialize(1);
#endif

UNUSED(ret);
return OK;
}
4 changes: 4 additions & 0 deletions drivers/sensors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ if(CONFIG_SENSORS)
list(APPEND SRCS bmm150_uorb.c)
endif()

if(CONFIG_SENSORS_AMG88XX)
list(APPEND SRCS amg88xx.c)
endif()

endif() # CONFIG_I2C

# These drivers depend on SPI support
Expand Down
32 changes: 32 additions & 0 deletions drivers/sensors/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1717,4 +1717,36 @@ config SENSORS_LTR308_THREAD_STACKSIZE

endif # SENSORS_LTR308

config SENSORS_AMG88XX
bool "AMG88xx infrared array sensor"
default n
select I2C
---help---
Enable driver support for AMG88xx infrared array sensor.

if SENSORS_AMG88XX

choice
prompt "AMG88xx AD_SELECT value"
default SENSOR_AMG88XX_AD_SELECT_0
---help---
AD SELECT sets the amg88xx i2c address
AD_SELECT tied to GND -> sensor address 0x68
AD_SELECT tied to VCC -> sensor address 0x69

config SENSOR_AMG88XX_AD_SELECT_0
bool "AD_SELECT tied to GND"

config SENSOR_AMG88XX_AD_SELECT_1
bool "AD_SELECT tied to VCC"

endchoice

config SENSOR_AMG88XX_ADDR
hex
default 0x68 if SENSOR_AMG88XX_AD_SELECT_0
default 0x69 if SENSOR_AMG88XX_AD_SELECT_1

endif # SENSORS_AMG88XX

endif # SENSORS
Loading

0 comments on commit d444ad4

Please sign in to comment.