Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensors/mi48: add support for mi48 thermal camera #3

Open
wants to merge 2 commits into
base: pre_mi48
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions os/board/rtl8721csm/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

CSRCS += rtl8721csm_boot.c
CSRCS += rtl8721csm_i2schar.c
ifeq ($(CONFIG_MI48),y)
CSRCS += rtl8721csm_mi48.c
endif
5 changes: 3 additions & 2 deletions os/board/rtl8721csm/src/rtl8721csm_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ void board_initialize(void)
ipc_table_init();
amebad_mount_partions();
board_gpio_initialize();
board_i2c_initialize();
board_spi_initialize();
// board_i2c_initialize();
// board_spi_initialize();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test

board_i2s_initialize();
rtl8721csm_mi48_initialize();
#ifdef CONFIG_WATCHDOG
amebad_wdg_initialize(CONFIG_WATCHDOG_DEVPATH, 5000);
#endif
Expand Down
189 changes: 189 additions & 0 deletions os/board/rtl8721csm/src/rtl8721csm_mi48.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/****************************************************************************
*
* Copyright 2023 Samsung Electronics All Rights Reserved.
*
* Licensed 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 <tinyara/config.h>
#include <tinyara/irq.h>
#include <tinyara/sensors/mi48.h>
#include <debug.h>
#include <errno.h>
#include "gpio_api.h"
#include "gpio_irq_api.h"

#ifdef CONFIG_MI48

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DEVNAME_FORMAT "/dev/img%d"

#define GPIO_RESET PB_2 // will set it to the right pin after wards
#define GPIO_DATA_READY PA_19

#define GPIO_UNSET 0
#define GPIO_SET 1

/* i2c config */
#define MI48_I2C_PORT 0
#define MI48_I2C_FREQ 100000
#define MI48_I2C_ADDRLEN 7

#define MI48_I2C_ADDR_H 0x41 /* need to set correct address */
#define MI48_I2C_ADDR_L 0x40

/* spi config */
#define MI48_SPI_PORT 0
#define MI48_SPI_FREQ 1000000
#define MI48_SPI_BPW 16
#define MI48_SPI_CS 0
#define MI48_SPI_MODE SPIDEV_MODE1

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

/****************************************************************************
* Private Types
****************************************************************************/

struct rtl8721csm_gpio_info_s {
gpio_t reset;
gpio_irq_t data_ready;
};

struct rtl8721csm_mi48_dev_s {
/* Lower level mi48 dev */
struct mi48_lower_s lower;

/* board specific gpio information */
struct rtl8721csm_gpio_info_s gpio_info;

/* gpio interrupt handler */
mi48_handler_t handler;
};

static int rtl8721csm_mi48_gpio_reset(struct mi48_lower_s *lower);
static int rtl8721csm_mi48_gpio_irq_attach(struct mi48_lower_s *lower, mi48_handler_t handler, FAR char *arg);
static int rtl8721csm_mi48_gpio_irq_enable(struct mi48_lower_s *lower, int enable);

static struct rtl8721csm_mi48_dev_s g_rtl8721csm_dev = {
.lower = {
.reset = rtl8721csm_mi48_gpio_reset,
.attach = rtl8721csm_mi48_gpio_irq_attach,
.enable = rtl8721csm_mi48_gpio_irq_enable,
.i2c_config = {
.frequency = MI48_I2C_FREQ,
.address = MI48_I2C_ADDR_L,
.addrlen = MI48_I2C_ADDRLEN,
},
.spi_config = {
.bpw = MI48_SPI_BPW,
.freq = MI48_SPI_FREQ,
.cs = MI48_SPI_CS,
.mode = MI48_SPI_MODE,
},
},
.gpio_info = {
.reset.pin = GPIO_RESET,
},
.handler = NULL

};

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

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

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

static int rtl8721csm_mi48_gpio_reset(struct mi48_lower_s *lower)
{
gpio_write(&(g_rtl8721csm_dev.gpio_info.reset), GPIO_UNSET);
HAL_Delay(100);
gpio_write(&(g_rtl8721csm_dev.gpio_info.reset), GPIO_SET);
HAL_Delay(1000);
return OK;
}

static void rtl8721csm_gpio_irq_handler(uint32_t id, gpio_irq_event event)
{
if (g_rtl8721csm_dev.handler) {
g_rtl8721csm_dev.handler((void *)id);
}
}

static int rtl8721csm_mi48_gpio_irq_attach(struct mi48_lower_s *lower, mi48_handler_t handler, FAR char *arg)
{
g_rtl8721csm_dev.handler = handler;
return OK;
}

static int rtl8721csm_mi48_gpio_irq_enable(struct mi48_lower_s *lower, int enable)
{
if (enable) {
gpio_irq_enable(&(g_rtl8721csm_dev.gpio_info.data_ready));
} else {
gpio_irq_disable(&(g_rtl8721csm_dev.gpio_info.data_ready));
}
return OK;
}

int rtl8721csm_mi48_initialize(void)
{
int result = 0;
FAR struct i2c_dev_s *i2c;
FAR struct spi_dev_s *spi;
char devpath[32];

gpio_irq_init(&(g_rtl8721csm_dev.gpio_info.data_ready), GPIO_DATA_READY, rtl8721csm_gpio_irq_handler, 1);
gpio_irq_set(&(g_rtl8721csm_dev.gpio_info.data_ready), IRQ_RISE, 1); // Rising edge trigger

i2c = up_i2cinitialize(MI48_I2C_PORT);
if (!i2c) {
result = -ENODEV;
goto done;
}

spi = up_spiinitialize(1);
if (!i2c) {
result = -ENODEV;
goto done;
}

/* register mi48 driver */
snprintf(devpath, sizeof(devpath), DEVNAME_FORMAT, 0);
if (mi48_register(devpath, &g_rtl8721csm_dev.lower, i2c, spi) != 0) {
goto done;
}

/* result is success */
result = 0;

done:
return result;
}

#endif /* CONFIG_MI48 */
7 changes: 7 additions & 0 deletions os/drivers/sensors/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ config SENSOR_PPD42NS_DEBUG
enable PPD42ns dust sensor driver's debug message

endif # SENSOR_PPD42NS

config MI48
bool "mi48 thermal imaging sensor"
depends on I2C && SPI
default n
---help---
enable mi48 thermal imaging sensor
4 changes: 4 additions & 0 deletions os/drivers/sensors/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ifeq ($(CONFIG_SENSOR_PPD42NS),y)
CSRCS += ppd42ns.c
endif

ifeq ($(CONFIG_MI48),y)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_SENSOR_MI48

CSRCS += mi48.c
endif

# Include sensor build support

DEPPATH += --dep-path sensors
Expand Down
Loading