mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 13:18:50 +08:00
Substantial changes to last PR which was not close to the coding standard. Files ran through tools/indent.sh.
This commit is contained in:
parent
ff5f1945ec
commit
900c32c021
3 changed files with 257 additions and 203 deletions
|
@ -106,7 +106,8 @@ static void stm32_i2c_register(int bus)
|
|||
ret = i2c_register(i2c, bus);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",bus, ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
|
||||
bus, ret);
|
||||
stm32l4_i2cbus_uninitialize(i2c);
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +135,6 @@ static void stm32_i2ctool(void)
|
|||
# define stm32_i2ctool()
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_app_initialize
|
||||
*
|
||||
|
@ -266,7 +266,6 @@ int board_app_initialize(uintptr_t arg)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_PWM
|
||||
/* Initialize PWM and register the PWM device. */
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@
|
|||
#endif
|
||||
|
||||
#define AS726X_INTEGRATION_TIME 50
|
||||
#define AS726X_GAIN 0b01 //Set gain to 64x
|
||||
#define AS726X_MEASURMENT_MODE 0b10 //One-shot reading of VBGYOR or RSTUVW
|
||||
#define AS726X_GAIN 0b01 /* Set gain to 64x */
|
||||
#define AS726X_MEASURMENT_MODE 0b10 /* One-shot reading of VBGYOR or RSTUVW */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
@ -81,27 +81,29 @@ struct as726x_dev_s
|
|||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
static float as726x_getCalibrated(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr);
|
||||
static int16_t as726x_getChannel(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr);
|
||||
|
||||
static float as726x_getcalibrated(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr);
|
||||
static int16_t as726x_getchannel(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr);
|
||||
|
||||
/* I2C Helpers */
|
||||
static uint8_t readRegister(FAR struct as726x_dev_s *priv, uint8_t addr);
|
||||
static uint8_t as726x_read8(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regval);
|
||||
static void writeRegister(FAR struct as726x_dev_s *priv, uint8_t addr, uint8_t val);
|
||||
static void as726x_write8(FAR struct as726x_dev_s *priv, uint8_t regaddr,
|
||||
uint8_t regval);
|
||||
|
||||
static uint8_t read_register(FAR struct as726x_dev_s *priv, uint8_t addr);
|
||||
static uint8_t as726x_read8(FAR struct as726x_dev_s *priv, uint8_t regval);
|
||||
static void write_register(FAR struct as726x_dev_s *priv, uint8_t addr,
|
||||
uint8_t val);
|
||||
static void as726x_write8(FAR struct as726x_dev_s *priv, uint8_t regaddr,
|
||||
uint8_t regval);
|
||||
|
||||
/* Character driver methods */
|
||||
|
||||
static int as726x_open(FAR struct file *filep);
|
||||
static int as726x_close(FAR struct file *filep);
|
||||
static int as726x_open(FAR struct file *filep);
|
||||
static int as726x_close(FAR struct file *filep);
|
||||
static ssize_t as726x_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t buflen);
|
||||
size_t buflen);
|
||||
static ssize_t as726x_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t buflen);
|
||||
FAR const char *buffer, size_t buflen);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
|
@ -109,17 +111,15 @@ static ssize_t as726x_write(FAR struct file *filep,
|
|||
|
||||
static const struct file_operations g_as726x_fops =
|
||||
{
|
||||
as726x_open, /* open */
|
||||
as726x_close, /* close */
|
||||
as726x_read, /* read */
|
||||
as726x_write, /* write */
|
||||
NULL, /* seek */
|
||||
NULL /* ioctl */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, NULL /* poll */
|
||||
#endif
|
||||
as726x_open, /* open */
|
||||
as726x_close, /* close */
|
||||
as726x_read, /* read */
|
||||
as726x_write, /* write */
|
||||
NULL, /* seek */
|
||||
NULL, /* ioctl */
|
||||
NULL /* poll */
|
||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||
, NULL /* unlink */
|
||||
, NULL /* unlink */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -128,43 +128,43 @@ static const struct file_operations g_as726x_fops =
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: as726x_getCalibrated
|
||||
* Name: as726x_getcalibrated
|
||||
*
|
||||
* Description:
|
||||
* Read calibrated value
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static float as726x_getCalibrated(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr)
|
||||
static float as726x_getcalibrated(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr)
|
||||
{
|
||||
uint8_t byte0 = as726x_read8(priv, regaddr + 0);
|
||||
uint8_t byte1 = as726x_read8(priv, regaddr + 1);
|
||||
uint8_t byte2 = as726x_read8(priv, regaddr + 2);
|
||||
uint8_t byte3 = as726x_read8(priv, regaddr + 3);
|
||||
|
||||
uint32_t colourData = ((uint32_t) byte0 << (8 * 3));
|
||||
colourData |= ((uint32_t) byte1 << (8 * 2));
|
||||
colourData |= ((uint32_t) byte2 << (8 * 1));
|
||||
colourData |= ((uint32_t) byte3 << (8 * 0));
|
||||
uint32_t colourdata = ((uint32_t) byte0 << (8 * 3));
|
||||
colourdata |= ((uint32_t) byte1 << (8 * 2));
|
||||
colourdata |= ((uint32_t) byte2 << (8 * 1));
|
||||
colourdata |= ((uint32_t) byte3 << (8 * 0));
|
||||
|
||||
return *((float*)(&colourData));
|
||||
return *((float *)(&colourdata));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: as726x_getChannel
|
||||
* Name: as726x_getchannel
|
||||
*
|
||||
* Description:
|
||||
* Read colour channel
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int16_t as726x_getChannel(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr)
|
||||
static int16_t as726x_getchannel(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr)
|
||||
{
|
||||
int16_t colourData = as726x_read8(priv, regaddr) << 8;
|
||||
colourData |= as726x_read8(priv, regaddr + 1);
|
||||
return colourData;
|
||||
int16_t colourdata = as726x_read8(priv, regaddr) << 8;
|
||||
colourdata |= as726x_read8(priv, regaddr + 1);
|
||||
return colourdata;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -175,65 +175,83 @@ static int16_t as726x_getChannel(FAR struct as726x_dev_s *priv,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static uint8_t readRegister(FAR struct as726x_dev_s *priv, uint8_t addr)
|
||||
static uint8_t read_register(FAR struct as726x_dev_s *priv, uint8_t addr)
|
||||
{
|
||||
struct i2c_config_s config;
|
||||
uint8_t regval = 0;
|
||||
int ret;
|
||||
|
||||
config.frequency = CONFIG_AS726X_I2C_FREQUENCY;
|
||||
config.address = AS726X_I2C_ADDR;
|
||||
config.addrlen = 7;
|
||||
config.address = AS726X_I2C_ADDR;
|
||||
config.addrlen = 7;
|
||||
|
||||
ret = i2c_write(priv->i2c, &config, &addr, 1);
|
||||
if(ret < 0) {
|
||||
snerr("ERROR: i2c_write failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: i2c_write failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = i2c_read(priv->i2c, &config, ®val, 1);
|
||||
if(ret < 0) {
|
||||
snerr("ERROR: i2c_read failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: i2c_read failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return regval;
|
||||
}
|
||||
|
||||
static uint8_t as726x_read8(FAR struct as726x_dev_s *priv,
|
||||
uint8_t regaddr)
|
||||
static uint8_t as726x_read8(FAR struct as726x_dev_s *priv, uint8_t regaddr)
|
||||
{
|
||||
|
||||
uint8_t status;
|
||||
|
||||
status = readRegister(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_RX_VALID) != 0) //There is data to be read
|
||||
{
|
||||
(void) readRegister(priv, AS72XX_SLAVE_READ_REG); //Read the byte but do nothing with it
|
||||
}
|
||||
status = read_register(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_RX_VALID) != 0)
|
||||
{
|
||||
/* There is data to be read.
|
||||
* Read the byte but do nothing with it.
|
||||
*/
|
||||
|
||||
//Wait for WRITE flag to clear
|
||||
while (1)
|
||||
{
|
||||
status = readRegister(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // If TX bit is clear, it is ok to write
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
(void)read_register(priv, AS72XX_SLAVE_READ_REG);
|
||||
}
|
||||
|
||||
// Send the virtual register address (bit 7 should be 0 to indicate we are reading a register).
|
||||
writeRegister(priv, AS72XX_SLAVE_WRITE_REG, regaddr);
|
||||
/* Wait for WRITE flag to clear */
|
||||
|
||||
//Wait for READ flag to be set
|
||||
while (1)
|
||||
{
|
||||
status = readRegister(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_RX_VALID) != 0) break; // Read data is ready.
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
status = read_register(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0)
|
||||
{
|
||||
break; /* If TX bit is clear, it is ok to write */
|
||||
}
|
||||
|
||||
uint8_t incoming = readRegister(priv, AS72XX_SLAVE_READ_REG);
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
|
||||
/* Send the virtual register address (bit 7 should be 0 to indicate we are
|
||||
* reading a register).
|
||||
*/
|
||||
|
||||
write_register(priv, AS72XX_SLAVE_WRITE_REG, regaddr);
|
||||
|
||||
/* Wait for READ flag to be set */
|
||||
|
||||
while (1)
|
||||
{
|
||||
status = read_register(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_RX_VALID) != 0)
|
||||
{
|
||||
break; /* Read data is ready. */
|
||||
}
|
||||
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
|
||||
uint8_t incoming = read_register(priv, AS72XX_SLAVE_READ_REG);
|
||||
return incoming;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: as726x_write8
|
||||
*
|
||||
|
@ -242,53 +260,73 @@ static uint8_t as726x_read8(FAR struct as726x_dev_s *priv,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void writeRegister(FAR struct as726x_dev_s *priv, uint8_t addr, uint8_t val)
|
||||
static void write_register(FAR struct as726x_dev_s *priv, uint8_t addr,
|
||||
uint8_t val)
|
||||
{
|
||||
struct i2c_config_s config;
|
||||
uint8_t msg[2] = { 0 };
|
||||
uint8_t msg[2] =
|
||||
{
|
||||
0
|
||||
};
|
||||
int ret;
|
||||
|
||||
config.frequency = CONFIG_AS726X_I2C_FREQUENCY;
|
||||
config.address = AS726X_I2C_ADDR;
|
||||
config.addrlen = 7;
|
||||
config.address = AS726X_I2C_ADDR;
|
||||
config.addrlen = 7;
|
||||
|
||||
msg[0] = addr;
|
||||
msg[1] = val;
|
||||
|
||||
ret = i2c_write(priv->i2c, &config, msg, 2);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: i2c_write failed: %d\n", ret);
|
||||
return;
|
||||
}
|
||||
{
|
||||
snerr("ERROR: i2c_write failed: %d\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void as726x_write8(FAR struct as726x_dev_s *priv, uint8_t regaddr,
|
||||
uint8_t regval)
|
||||
uint8_t regval)
|
||||
{
|
||||
|
||||
uint8_t status;
|
||||
|
||||
while (1)
|
||||
{
|
||||
status = readRegister(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // No inbound TX pending at slave. Okay to write now.
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
{
|
||||
status = read_register(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0)
|
||||
{
|
||||
/* No inbound TX pending at slave. Okay to write now. */
|
||||
|
||||
// Send the virtual register address (setting bit 7 to indicate we are writing to a register).
|
||||
writeRegister(priv, AS72XX_SLAVE_WRITE_REG, (regaddr | 0x80));
|
||||
break;
|
||||
}
|
||||
|
||||
//Wait for WRITE register to be empty
|
||||
while (1)
|
||||
{
|
||||
status = readRegister(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0) break; // No inbound TX pending at slave. Okay to write now.
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
|
||||
// Send the data to complete the operation.
|
||||
writeRegister(priv, AS72XX_SLAVE_WRITE_REG, regval);
|
||||
/* Send the virtual register address (setting bit 7 to indicate we are
|
||||
* writing to a register).
|
||||
*/
|
||||
|
||||
write_register(priv, AS72XX_SLAVE_WRITE_REG, (regaddr | 0x80));
|
||||
|
||||
/* Wait for WRITE register to be empty */
|
||||
|
||||
while (1)
|
||||
{
|
||||
status = read_register(priv, AS72XX_SLAVE_STATUS_REG);
|
||||
if ((status & AS72XX_SLAVE_TX_VALID) == 0)
|
||||
{
|
||||
/* No inbound TX pending at slave. Okay to write now. */
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(AS726X_POLLING_DELAY);
|
||||
}
|
||||
|
||||
/* Send the data to complete the operation. */
|
||||
|
||||
write_register(priv, AS72XX_SLAVE_WRITE_REG, regval);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -322,14 +360,15 @@ static int as726x_close(FAR struct file *filep)
|
|||
****************************************************************************/
|
||||
|
||||
static ssize_t as726x_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t buflen)
|
||||
size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct as726x_dev_s *priv = inode->i_private;
|
||||
FAR struct as726x_sensor_data_s *data =
|
||||
(FAR struct as726x_sensor_data_s *)buffer;
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct as726x_dev_s *priv = inode->i_private;
|
||||
FAR struct as726x_sensor_data_s *data =
|
||||
(FAR struct as726x_sensor_data_s *)buffer;
|
||||
|
||||
/* Check if the user is reading the right size */
|
||||
|
||||
if (buflen < sizeof(FAR struct as726x_sensor_data_s))
|
||||
{
|
||||
snerr("ERROR: Not enough memory for reading all channels.\n");
|
||||
|
@ -337,23 +376,23 @@ static ssize_t as726x_read(FAR struct file *filep, FAR char *buffer,
|
|||
}
|
||||
else
|
||||
{
|
||||
data->v_r_value = as726x_getChannel(priv, AS726X_V_R);
|
||||
data->b_s_value = as726x_getChannel(priv, AS726X_B_S);
|
||||
data->g_t_value = as726x_getChannel(priv, AS726X_G_T);
|
||||
data->y_u_value = as726x_getChannel(priv, AS726X_Y_U);
|
||||
data->o_v_value = as726x_getChannel(priv, AS726X_O_V);
|
||||
data->r_w_value = as726x_getChannel(priv, AS726X_R_W);
|
||||
data->v_r_value = as726x_getchannel(priv, AS726X_V_R);
|
||||
data->b_s_value = as726x_getchannel(priv, AS726X_B_S);
|
||||
data->g_t_value = as726x_getchannel(priv, AS726X_G_T);
|
||||
data->y_u_value = as726x_getchannel(priv, AS726X_Y_U);
|
||||
data->o_v_value = as726x_getchannel(priv, AS726X_O_V);
|
||||
data->r_w_value = as726x_getchannel(priv, AS726X_R_W);
|
||||
}
|
||||
|
||||
return buflen;
|
||||
}
|
||||
|
||||
// /****************************************************************************
|
||||
// * Name: as726x_write
|
||||
// ****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: as726x_write
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t as726x_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t buflen)
|
||||
FAR const char *buffer, size_t buflen)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
@ -380,6 +419,8 @@ static ssize_t as726x_write(FAR struct file *filep,
|
|||
|
||||
int as726x_register(FAR const char *devpath, FAR struct i2c_master_s *i2c)
|
||||
{
|
||||
uint8_t _sensor_version;
|
||||
uint8_t value;
|
||||
int ret;
|
||||
|
||||
/* Sanity check */
|
||||
|
@ -392,75 +433,80 @@ int as726x_register(FAR const char *devpath, FAR struct i2c_master_s *i2c)
|
|||
(FAR struct as726x_dev_s *)kmm_malloc(sizeof(struct as726x_dev_s));
|
||||
|
||||
if (priv == NULL)
|
||||
{
|
||||
snerr("ERROR: Failed to allocate instance\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
{
|
||||
snerr("ERROR: Failed to allocate instance\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->i2c = i2c;
|
||||
priv->i2c = i2c;
|
||||
priv->addr = AS726X_I2C_ADDR;
|
||||
|
||||
uint8_t _sensorVersion = as726x_read8(priv, AS726x_HW_VERSION);
|
||||
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F) //HW version for AS7262 and AS7263
|
||||
{
|
||||
snerr("ID (should be 0x3E or 0x3F): 0x %d\n", ret);
|
||||
}
|
||||
/* Check HW version for AS7262 and AS7263 */
|
||||
|
||||
// /* Initialize the device */
|
||||
_sensor_version = as726x_read8(priv, AS726x_HW_VERSION);
|
||||
if (_sensor_version != 0x3e && _sensor_version != 0x3f)
|
||||
{
|
||||
snerr("ID (should be 0x3e or 0x3f): 0x %d\n", ret);
|
||||
}
|
||||
|
||||
// /* Read the register value toogle and disable led */
|
||||
/* Initialize the device
|
||||
* Read the register value toggle and disable led
|
||||
*/
|
||||
|
||||
ret = as726x_read8(priv, AS726x_LED_CONTROL);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t value = ret;
|
||||
|
||||
value &= ~(1 << 0); //Clear the bit
|
||||
value = ret;
|
||||
value &= ~(1 << 0); /* Clear the bit */
|
||||
|
||||
as726x_write8(priv, AS726x_LED_CONTROL, value);
|
||||
|
||||
//If you use Mode 2 or 3 (all the colors) then integration time is double. 140*2 = 280ms between readings.
|
||||
//50 * 2.8ms = 140ms. 0 to 255 is valid.
|
||||
/* If you use Mode 2 or 3 (all the colors) then integration time is double.
|
||||
* 140*2 = 280ms between readings.
|
||||
* 50 * 2.8ms = 140ms. 0 to 255 is valid.
|
||||
*/
|
||||
|
||||
as726x_write8(priv, AS726x_INT_T, AS726X_INTEGRATION_TIME);
|
||||
|
||||
ret = as726x_read8(priv, AS726x_CONTROL_SETUP);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
value = ret;
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
value &= 0b11001111; //Clear GAIN bits
|
||||
value |= (AS726X_GAIN << 4); //Set GAIN bits with user's choice
|
||||
value = ret;
|
||||
value &= 0 b11001111; /* Clear GAIN bits */
|
||||
value |= (AS726X_GAIN << 4); /* Set GAIN bits with user's choice */
|
||||
|
||||
as726x_write8(priv, AS726x_CONTROL_SETUP, value);
|
||||
|
||||
ret = as726x_read8(priv, AS726x_CONTROL_SETUP);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
value = ret;
|
||||
{
|
||||
snerr("ERROR: Failed to initialize the AS726X!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
value &= 0b11110011; //Clear BANK bits
|
||||
value |= (AS726X_MEASURMENT_MODE << 2); //Set BANK bits with user's choice
|
||||
value = ret;
|
||||
value &= 0 b11110011; /* Clear BANK bits */
|
||||
value |= (AS726X_MEASURMENT_MODE << 2); /* Set BANK bits with user's
|
||||
* choice */
|
||||
|
||||
as726x_write8(priv, AS726x_CONTROL_SETUP, value);
|
||||
|
||||
// /* Register the character driver */
|
||||
/* Register the character driver */
|
||||
|
||||
ret = register_driver(devpath, &g_as726x_fops, 0666, priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to register driver: %d\n", ret);
|
||||
kmm_free(priv);
|
||||
}
|
||||
{
|
||||
snerr("ERROR: Failed to register driver: %d\n", ret);
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -55,58 +55,67 @@
|
|||
|
||||
/* Device I2C Address */
|
||||
|
||||
// #define AS726X_I2C_DATA_LSB_CMD_ADDR 0x38
|
||||
// #define AS726X_I2C_DATA_MSB_ADDR 0x39
|
||||
#if 0
|
||||
#define AS726X_I2C_DATA_LSB_CMD_ADDR 0x38
|
||||
#define AS726X_I2C_DATA_MSB_ADDR 0x39
|
||||
#endif
|
||||
|
||||
#define AS726X_I2C_ADDR 0x49 //7-bit unshifted default I2C Address
|
||||
#define SENSORTYPE_AS7262 0x3E
|
||||
#define SENSORTYPE_AS7263 0x3F
|
||||
#define AS726X_I2C_ADDR 0x49 /* 7-bit unshifted default I2C Address */
|
||||
#define SENSORTYPE_AS7262 0x3e
|
||||
#define SENSORTYPE_AS7263 0x3f
|
||||
|
||||
//Register addresses
|
||||
#define AS726x_DEVICE_TYPE 0x00
|
||||
#define AS726x_HW_VERSION 0x01
|
||||
#define AS726x_CONTROL_SETUP 0x04
|
||||
#define AS726x_INT_T 0x05
|
||||
#define AS726x_DEVICE_TEMP 0x06
|
||||
#define AS726x_LED_CONTROL 0x07
|
||||
/* Register addresses */
|
||||
|
||||
#define AS726x_DEVICE_TYPE 0x00
|
||||
#define AS726x_HW_VERSION 0x01
|
||||
#define AS726x_CONTROL_SETUP 0x04
|
||||
#define AS726x_INT_T 0x05
|
||||
#define AS726x_DEVICE_TEMP 0x06
|
||||
#define AS726x_LED_CONTROL 0x07
|
||||
|
||||
#define AS72XX_SLAVE_STATUS_REG 0x00
|
||||
#define AS72XX_SLAVE_WRITE_REG 0x01
|
||||
#define AS72XX_SLAVE_READ_REG 0x02
|
||||
#define AS72XX_SLAVE_WRITE_REG 0x01
|
||||
#define AS72XX_SLAVE_READ_REG 0x02
|
||||
|
||||
//The same register locations are shared between the AS7262 (V,B,G,Y,O,R) and AS7263 (R,S,T,U,V,W)
|
||||
//AS7262 and AS7263 registers
|
||||
#define AS726X_V_R 0x08
|
||||
#define AS726X_B_S 0x0A
|
||||
#define AS726X_G_T 0x0C
|
||||
#define AS726X_Y_U 0x0E
|
||||
#define AS726X_O_V 0x10
|
||||
#define AS726X_R_W 0x12
|
||||
#define AS726X_V_R_CAL 0x14
|
||||
#define AS726X_B_S_CAL 0x18
|
||||
#define AS726X_G_T_CAL 0x1C
|
||||
#define AS726X_Y_U_CAL 0x20
|
||||
#define AS726X_O_V_CAL 0x24
|
||||
#define AS726X_R_W_CAL 0x28
|
||||
/* The same register locations are shared between the AS7262 (V,B,G,Y,O,R)
|
||||
* and AS7263 (R,S,T,U,V,W) AS7262 and AS7263 registers
|
||||
*/
|
||||
|
||||
#define AS72XX_SLAVE_TX_VALID 0x02
|
||||
#define AS72XX_SLAVE_RX_VALID 0x01
|
||||
#define AS726X_V_R 0x08
|
||||
#define AS726X_B_S 0x0a
|
||||
#define AS726X_G_T 0x0c
|
||||
#define AS726X_Y_U 0x0e
|
||||
#define AS726X_O_V 0x10
|
||||
#define AS726X_R_W 0x12
|
||||
#define AS726X_V_R_CAL 0x14
|
||||
#define AS726X_B_S_CAL 0x18
|
||||
#define AS726X_G_T_CAL 0x1c
|
||||
#define AS726X_Y_U_CAL 0x20
|
||||
#define AS726X_O_V_CAL 0x24
|
||||
#define AS726X_R_W_CAL 0x28
|
||||
|
||||
#define SENSORTYPE_AS7262 0x3E
|
||||
#define SENSORTYPE_AS7263 0x3F
|
||||
#define AS72XX_SLAVE_TX_VALID 0x02
|
||||
#define AS72XX_SLAVE_RX_VALID 0x01
|
||||
|
||||
#define AS726X_POLLING_DELAY 5000 //Amount of ms to wait between checking for virtual register changes
|
||||
#define SENSORTYPE_AS7262 0x3e
|
||||
#define SENSORTYPE_AS7263 0x3f
|
||||
|
||||
// #define AS726X_CMD_SD 0x01 /* Shutdown command */
|
||||
// #define AS726X_CMD_RSV 0x02
|
||||
// #define AS726X_CMD_IT_0_5T 0x00 /* IT1=0 : IT0=0 */
|
||||
// #define AS726X_CMD_IT_1T 0x04 /* IT1=0 : IT0=1 */
|
||||
// #define AS726X_CMD_IT_2T 0x08 /* IT1=1 : IT0=0 */
|
||||
// #define AS726X_CMD_IT_4T 0x0c /* IT1=1 : IT0=1 */
|
||||
// #define AS726X_CMD_ACK_THD 0x10 /* Acknowledge thresold:
|
||||
// 0 = 102 steps
|
||||
// 1 = 145 steps */
|
||||
// #define AS726X_CMD_ACK 0x20 /* Acknowledge activity */
|
||||
/* Amount of ms to wait between checking for virtual register changes */
|
||||
|
||||
#define AS726X_POLLING_DELAY 5000
|
||||
|
||||
#if 0
|
||||
#define AS726X_CMD_SD 0x01 /* Shutdown command */
|
||||
#define AS726X_CMD_RSV 0x02
|
||||
#define AS726X_CMD_IT_0_5T 0x00 /* IT1=0 : IT0=0 */
|
||||
#define AS726X_CMD_IT_1T 0x04 /* IT1=0 : IT0=1 */
|
||||
#define AS726X_CMD_IT_2T 0x08 /* IT1=1 : IT0=0 */
|
||||
#define AS726X_CMD_IT_4T 0x0c /* IT1=1 : IT0=1 */
|
||||
#define AS726X_CMD_ACK_THD 0x10 /* Acknowledge thresold:
|
||||
* 0 = 102 steps
|
||||
* 1 = 145 steps */
|
||||
#define AS726X_CMD_ACK 0x20 /* Acknowledge activity */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
|
|
Loading…
Reference in a new issue