pkarashchenko commented on code in PR #6412: URL: https://github.com/apache/incubator-nuttx/pull/6412#discussion_r895330017
########## drivers/sensors/as5048a.c: ########## @@ -0,0 +1,632 @@ +/**************************************************************************** + * drivers/sensors/as5048a.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 <assert.h> +#include <errno.h> +#include <debug.h> +#include <stdlib.h> + +#include <nuttx/kmalloc.h> +#include <nuttx/fs/fs.h> +#include <nuttx/spi/spi.h> +#include <nuttx/sensors/as5048a.h> + +#if defined(CONFIG_SENSORS_AS5048A) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct as5048a_dev_s +{ + struct qe_lowerhalf_s lower; /* AS5048A quadrature encoder lower half */ + FAR struct spi_dev_s *spi; /* SPI interface */ + + /* Since multiple AS5048A can be connected to the same SPI bus we need + * to use multiple spi device ids which are employed by NuttX to select/ + * deselect the desired AS5048A chip via their chip select inputs. + */ + + int spi_devid; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int as5048a_writeu16(FAR struct as5048a_dev_s *priv, + uint16_t regaddr, uint16_t regval); +static int as5048a_exchange(FAR struct as5048a_dev_s *priv, + uint16_t regaddr, FAR uint16_t *regval); +static uint16_t calc_even_parity(uint16_t value); +static int as5048a_readzero(FAR struct as5048a_dev_s *priv, + FAR uint16_t *zero); +static int as5048a_writezero(FAR struct as5048a_dev_s *priv, uint16_t zero); +static int as5048a_readagc(FAR struct as5048a_dev_s *priv, + FAR uint16_t *agc); +static int as5048a_readdiag(FAR struct as5048a_dev_s *priv, + FAR uint16_t *diag); +static int as5048a_readmag(FAR struct as5048a_dev_s *priv, + FAR uint16_t *mag); +static int as5048a_readang(FAR struct as5048a_dev_s *priv, + FAR uint16_t *ang); + +/* Character Driver Methods */ + +static int as5048a_setup(FAR struct qe_lowerhalf_s *lower); +static int as5048a_shutdown(FAR struct qe_lowerhalf_s *lower); +static int as5048a_position(FAR struct qe_lowerhalf_s *lower, + FAR int32_t *pos); +static int as5048a_reset(FAR struct qe_lowerhalf_s *lower); +static int as5048a_ioctl(FAR struct qe_lowerhalf_s *lower, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct qe_ops_s g_qeops = +{ + .setup = as5048a_setup, + .shutdown = as5048a_shutdown, + .position = as5048a_position, + .setposmax = NULL, /* not supported yet */ + .reset = as5048a_reset, + .setindex = NULL, /* not supported yet */ + .ioctl = as5048a_ioctl Review Comment: The code in common folder has C89 requirement. The platform code can use features supported by platform compiler -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
