xiaoxiang781216 commented on code in PR #10441: URL: https://github.com/apache/nuttx/pull/10441#discussion_r1320789631
########## boards/xtensa/esp32/common/src/esp32_wiegand.c: ########## @@ -0,0 +1,175 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/src/esp32_wiegand.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 <debug.h> +#include <errno.h> +#include <stdbool.h> +#include <stdio.h> + +#include <nuttx/wiegand/wiegand.h> + +#include "esp32_gpio.h" +#include "hardware/esp32_gpio_sigmap.h" + +#ifndef CONFIG_ESP32_GPIO_IRQ +#error "This drive needs to enable config of CONFIG_ESP32_GPIO_IRQ," \ + " please enable it" +#endif + +#define GPIO_DATA_0 22 +#define GPIO_DATA_1 23 +#define GPIO_DATA_NUM 2 + +struct esp32_wiegand_config_s +{ + struct wiegand_config_s config; + void *arg; + xcpt_t isr; +}; + +int gpio_data [GPIO_DATA_NUM] = +{ + GPIO_DATA_0, + GPIO_DATA_1 +}; + +static int wiegand_irq_attach(struct wiegand_config_s *dev, xcpt_t isr, + void *arg); +static void wiegand_irq_enable(struct wiegand_config_s *dev, bool enable); +static bool wiegand_read_data(const struct wiegand_config_s *dev, int index); + +static struct esp32_wiegand_config_s wiegand_config = +{ + .config = + { + .get_data = wiegand_read_data, + .irq_attach = wiegand_irq_attach, + .irq_enable = wiegand_irq_enable, + }, +}; + +static bool wiegand_read_data(const struct wiegand_config_s *dev, int index) Review Comment: Here is the basic structure: 1. Define wiegand_ops_s and wiegand_lowerhalf_s like watchdog/gpio: https://github.com/apache/nuttx/blob/master/include/nuttx/timers/watchdog.h#L117-L180 https://github.com/apache/nuttx/blob/master/include/nuttx/ioexpander/gpio.h#L84-L166 2. Implement wiegand_register which implement file_operations on top of wiegand_ops_s as wiegand_upperhalf_s like: https://github.com/apache/nuttx/blob/master/drivers/timers/watchdog.c#L75-L133 https://github.com/apache/nuttx/blob/master/drivers/timers/watchdog.c#L732-L801 https://github.com/apache/nuttx/blob/master/drivers/ioexpander/gpio.c#L46-L67 https://github.com/apache/nuttx/blob/master/drivers/ioexpander/gpio.c#L539-L638 3. Write a wiegand_lowerhalf_s on top of ioexpander_dev_s like gpio: https://github.com/apache/nuttx/blob/master/drivers/ioexpander/gpio_lower_half.c Finally, register this lowerhalf in your board file. -- 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]
