2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* boards/arm/stm32/common/src/stm32_bh1750.c
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
2021-03-19 09:05:04 +01:00
|
|
|
* 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
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
2021-03-19 09:05:04 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
2021-03-19 09:05:04 +01:00
|
|
|
* 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.
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2016-04-15 16:20:33 +02:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2016-04-15 16:20:33 +02:00
|
|
|
* Included Files
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2016-04-15 16:20:33 +02:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2020-05-12 22:19:26 +02:00
|
|
|
#include <stdio.h>
|
2016-04-15 16:20:33 +02:00
|
|
|
|
|
|
|
#include <nuttx/spi/spi.h>
|
2020-05-12 22:19:26 +02:00
|
|
|
#include <arch/board/board.h>
|
2016-04-15 16:20:33 +02:00
|
|
|
#include <nuttx/sensors/bh1750fvi.h>
|
|
|
|
|
|
|
|
#include "stm32.h"
|
|
|
|
#include "stm32_i2c.h"
|
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2016-04-15 16:20:33 +02:00
|
|
|
* Pre-processor Definitions
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2016-04-15 16:20:33 +02:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2016-04-15 16:20:33 +02:00
|
|
|
* Public Functions
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2016-04-15 16:20:33 +02:00
|
|
|
|
2019-08-19 17:16:08 +02:00
|
|
|
/****************************************************************************
|
2016-04-15 16:20:33 +02:00
|
|
|
* Name: stm32_bh1750initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2022-07-26 09:48:48 +02:00
|
|
|
* Initialize and register the BH1750FVI Ambient Light driver.
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2020-05-12 22:19:26 +02:00
|
|
|
* devno - The device number, used to build the device path as /dev/lightN
|
|
|
|
* busno - The I2C bus number
|
2016-04-15 16:20:33 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
*
|
2019-08-19 17:16:08 +02:00
|
|
|
****************************************************************************/
|
2016-04-15 16:20:33 +02:00
|
|
|
|
2020-05-12 22:19:26 +02:00
|
|
|
int board_bh1750_initialize(int devno, int busno)
|
2016-04-15 16:20:33 +02:00
|
|
|
{
|
2022-04-17 08:01:48 +02:00
|
|
|
struct i2c_master_s *i2c;
|
2016-04-15 16:20:33 +02:00
|
|
|
int ret;
|
|
|
|
|
2016-06-13 01:02:46 +02:00
|
|
|
sninfo("Initializing BH1750FVI!\n");
|
2016-04-15 16:20:33 +02:00
|
|
|
|
|
|
|
/* Initialize I2C */
|
|
|
|
|
2020-05-12 22:19:26 +02:00
|
|
|
i2c = stm32_i2cbus_initialize(busno);
|
2016-04-15 16:20:33 +02:00
|
|
|
|
|
|
|
if (!i2c)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then register the barometer sensor */
|
|
|
|
|
|
|
|
ret = bh1750fvi_register(devpath, i2c, BH1750FVI_I2C_ADDR);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-07-26 09:48:48 +02:00
|
|
|
snerr("ERROR: Error registering BH1750FVI\n");
|
2016-04-15 16:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|