You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/14 23:37:53 UTC
incubator-mynewt-core git commit: this is a simple blocking SPI
interface.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 963874bef -> 68655ef90
this is a simple blocking SPI interface.
It allows a SPI transfer of 1 byte with a blocking interface.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/68655ef9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/68655ef9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/68655ef9
Branch: refs/heads/develop
Commit: 68655ef9000dcb7d0ccc33a6d4d652e94868e438
Parents: 963874b
Author: Paul Dietrich <pa...@yahoo.com>
Authored: Tue Apr 12 17:29:23 2016 -0700
Committer: Paul Dietrich <pa...@yahoo.com>
Committed: Thu Apr 14 09:41:52 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_spi.h | 81 +++++++++++++++++++++++++++++++++++
hw/hal/include/hal/hal_spi_int.h | 69 +++++++++++++++++++++++++++++
hw/hal/src/hal_spi.c | 44 +++++++++++++++++++
3 files changed, 194 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68655ef9/hw/hal/include/hal/hal_spi.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_spi.h b/hw/hal/include/hal/hal_spi.h
new file mode 100644
index 0000000..6bfbde4
--- /dev/null
+++ b/hw/hal/include/hal/hal_spi.h
@@ -0,0 +1,81 @@
+/**
+ * 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.
+ */
+
+
+#ifndef HAL_SPI_H
+#define HAL_SPI_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+#include <bsp/bsp_sysid.h>
+
+struct hal_spi;
+
+enum hal_spi_data_mode{
+ HAL_SPI_MODE0,
+ HAL_SPI_MODE1,
+ HAL_SPI_MODE2,
+ HAL_SPI_MODE3,
+} ;
+
+enum hal_spi_data_order{
+ HAL_SPI_MSB_FIRST,
+ HAL_SPI_LSB_FIRST,
+} ;
+
+enum hal_spi_word_size{
+ HAL_SPI_WORD_SIZE_8BIT,
+ HAL_SPI_WORD_SIZE_9BIT,
+};
+
+typedef uint32_t hal_spi_baudrate;
+
+/* since one spi device can control multiple devices, some configuration
+ * can be changed on the fly from the hal */
+struct hal_spi_settings {
+ enum hal_spi_data_mode data_mode;
+ enum hal_spi_data_order data_order;
+ enum hal_spi_word_size word_size;
+ hal_spi_baudrate baudrate;
+};
+
+/* initialize the SPI on the corresponding BSP device. Returns a pointer
+ * to the SPI object to use for the methods below. Returns NULL on
+ * error */
+struct hal_spi *
+hal_spi_init(enum system_device_id sysid);
+
+/* configure the spi */
+int
+hal_spi_config(struct hal_spi *pspi, struct hal_spi_settings *psettings);
+
+/* do a blocking master spi transfer */
+int
+hal_spi_master_transfer(struct hal_spi *psdi, uint16_t tx);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_SPI_H */
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68655ef9/hw/hal/include/hal/hal_spi_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_spi_int.h b/hw/hal/include/hal/hal_spi_int.h
new file mode 100644
index 0000000..f30afdd
--- /dev/null
+++ b/hw/hal/include/hal/hal_spi_int.h
@@ -0,0 +1,69 @@
+/**
+ * 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 <bsp/bsp_sysid.h>
+
+
+#ifndef HAL_SPI_INT_H
+#define HAL_SPI_INT_H
+
+struct hal_spi;
+
+/* configure the spi */
+int
+hal_spi_config(struct hal_spi *pspi, struct hal_spi_settings *psettings);
+
+/* do a blocking master spi transfer */
+int
+hal_spi_master_transfer(struct hal_spi *psdi, uint16_t tx);
+
+/* These functions make up the driver API for DAC devices. All
+ * DAC devices with Mynewt support implement this interface */
+struct hal_spi_funcs
+{
+ int (*hspi_config) (struct hal_spi *pspi, struct hal_spi_settings *psettings);
+ int (*hspi_master_transfer) (struct hal_spi *psdi, uint16_t tx);
+};
+
+/* This is the internal device representation for a hal_spi device.
+ *
+ * Its main goal is to wrap the const drivers in a non-const structure.
+ * Thus these can be made on the stack and wrapped with other non-const
+ * structures.
+ *
+ * For example, if you are creating a spi driver you can use
+ *
+ * struct my_spi_driver {
+ * struct hal_spi parent;
+ * int my_stuff 1;
+ * char *mybuff;
+ * };
+ *
+ * See the native MCU and BSP for examples
+ */
+struct hal_spi
+{
+ const struct hal_spi_funcs *driver_api;
+};
+
+/* The BSP must implement this factory to get devices for the
+ * application. */
+extern struct hal_spi *
+bsp_get_hal_spi(enum system_device_id sysid);
+
+#endif /* HAL_SPI_INT_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/68655ef9/hw/hal/src/hal_spi.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_spi.c b/hw/hal/src/hal_spi.c
new file mode 100644
index 0000000..5b53150
--- /dev/null
+++ b/hw/hal/src/hal_spi.c
@@ -0,0 +1,44 @@
+/**
+ * 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 <hal/hal_spi.h>
+#include <hal/hal_spi_int.h>
+
+struct hal_spi *
+hal_spi_init(enum system_device_id pin)
+{
+ return bsp_get_hal_spi(pin);
+}
+
+int
+hal_spi_config(struct hal_spi *pspi, struct hal_spi_settings *psettings)
+{
+ if (pspi && pspi->driver_api && pspi->driver_api->hspi_config) {
+ return pspi->driver_api->hspi_config(pspi, psettings);
+ }
+ return -1;
+}
+
+int
+hal_spi_master_transfer(struct hal_spi *pspi, uint16_t val)
+{
+ if (pspi && pspi->driver_api && pspi->driver_api->hspi_master_transfer) {
+ return pspi->driver_api->hspi_master_transfer(pspi, val);
+ }
+ return -1;
+}