You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2021/06/09 13:57:26 UTC

[GitHub] [mynewt-core] kasjer commented on a change in pull request #2605: hw/drivers/uart: Add MAX3107 driver

kasjer commented on a change in pull request #2605:
URL: https://github.com/apache/mynewt-core/pull/2605#discussion_r648328693



##########
File path: hw/drivers/uart/max3107/src/max3107.c
##########
@@ -0,0 +1,1090 @@
+/*
+ * 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.
+ */
+
+#include <assert.h>
+#include <string.h>
+
+#include <os/mynewt.h>
+#include <bsp/bsp.h>
+#include <hal/hal_gpio.h>
+#include <hal/hal_uart.h>
+
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+#include <bus/drivers/spi_common.h>
+#endif
+#include <max3107/max3107.h>
+#include "max3107_priv.h"
+
+#include <uart/uart.h>
+
+static inline int
+max3107_lock(struct max3107_dev *dev)
+{
+    return os_error_to_sys(os_mutex_pend(&dev->lock,
+                                         os_time_ms_to_ticks32(MYNEWT_VAL(MAX3107_LOCK_TIMEOUT))));
+}
+
+static inline void
+max3107_unlock(struct max3107_dev *dev)
+{
+    int rc = os_mutex_release(&dev->lock);
+    assert(rc == 0);
+}
+
+void
+max3107_cs_activate(struct max3107_dev *dev)
+{
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    struct bus_spi_node *node = (struct bus_spi_node *)&dev->dev;
+    hal_gpio_write(node->pin_cs, 0);
+#else
+    hal_gpio_write(dev->cfg.ss_pin, 0);
+#endif
+}
+
+void
+max3107_cs_deactivate(struct max3107_dev *dev)
+{
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    struct bus_spi_node *node = &dev->dev;
+    hal_gpio_write(node->pin_cs, 1);
+#else
+    hal_gpio_write(dev->cfg.ss_pin, 1);
+#endif
+}
+
+int
+max3107_read_regs(struct max3107_dev *dev, uint8_t addr, void *buf, uint32_t size)
+{
+    int rc;
+    bool locked;
+#if !MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    uint8_t fast_buf[8];
+#endif
+
+    rc = max3107_lock(dev);
+    locked = rc == 0;

Review comment:
       yes




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org