Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/sterly_refactor 2fcf6aa87 -> 93d29b847


remove DAC,ADC and PWM adcs.  remove sysid and int/ext concept from I2C and SPI 
adcs.  add drivers / device framework first cut.  this is an interim checkin.


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/93d29b84
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/93d29b84
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/93d29b84

Branch: refs/heads/sterly_refactor
Commit: 93d29b8476f16877518ba117ff1894931263716e
Parents: db980b2
Author: Sterling Hughes <[email protected]>
Authored: Sun Jul 31 21:58:14 2016 -0700
Committer: Sterling Hughes <[email protected]>
Committed: Sun Jul 31 21:58:57 2016 -0700

----------------------------------------------------------------------
 .../adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h |  27 +++
 drivers/adc/adc_nrf52/pkg.yml                   |  29 +++
 drivers/adc/adc_nrf52/src/adc_nrf52.c           |  65 +++++++
 drivers/adc/include/adc/adc.h                   |  43 +++++
 drivers/adc/pkg.yml                             |  27 +++
 drivers/adc/src/adc.c                           |  22 +++
 hw/hal/include/hal/hal_adc.h                    |  73 --------
 hw/hal/include/hal/hal_adc_int.h                |  71 --------
 hw/hal/include/hal/hal_dac.h                    |  94 ----------
 hw/hal/include/hal/hal_dac_int.h                |  74 --------
 hw/hal/include/hal/hal_i2c.h                    |  15 +-
 hw/hal/include/hal/hal_i2c_int.h                |  53 ------
 hw/hal/include/hal/hal_pwm.h                    |  84 ---------
 hw/hal/include/hal/hal_pwm_int.h                |  59 -------
 hw/hal/include/hal/hal_spi.h                    |   3 +-
 hw/hal/include/hal/hal_spi_int.h                |  78 --------
 hw/hal/src/hal_adc.c                            |  78 --------
 hw/hal/src/hal_dac.c                            |  96 ----------
 hw/hal/src/hal_i2c.c                            |  77 --------
 hw/hal/src/hal_pwm.c                            |  74 --------
 hw/hal/src/hal_spi.c                            |  44 -----
 libs/os/include/os/os_dev.h                     |  84 +++++++++
 libs/os/src/os.c                                |   4 +
 libs/os/src/os_dev.c                            | 177 +++++++++++++++++++
 24 files changed, 486 insertions(+), 965 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h 
b/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
new file mode 100644
index 0000000..898503b
--- /dev/null
+++ b/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
@@ -0,0 +1,27 @@
+/*
+ * 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 __ADC_NRF52_H__
+#define __ADC_NRF52_H__
+
+#include <adc/adc.h>
+
+int nrf52_adc_dev_init(struct os_dev *);
+
+#endif /* __ADC_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/adc_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf52/pkg.yml b/drivers/adc/adc_nrf52/pkg.yml
new file mode 100644
index 0000000..487b23b
--- /dev/null
+++ b/drivers/adc/adc_nrf52/pkg.yml
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+pkg.name: drivers/adc/adc_nrf52
+pkg.description: ADC driver for the NRF52
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+pkg.deps.TEST:
+   - hw/hal
+   - hw/mcu/nordic
+   - drivers/adc
+   - libs/testutil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/adc_nrf52/src/adc_nrf52.c
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf52/src/adc_nrf52.c 
b/drivers/adc/adc_nrf52/src/adc_nrf52.c
new file mode 100644
index 0000000..c8e5741
--- /dev/null
+++ b/drivers/adc/adc_nrf52/src/adc_nrf52.c
@@ -0,0 +1,65 @@
+/*
+ * 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 <adc/adc.h>
+
+/* Nordic headers */
+#include <nrf.h>
+#include <nrf_drv_saadc.h>
+#include <app_error.h>
+
+
+static int
+nrf52_adc_configure(struct adc_dev *dev, void *cfgdata)
+{
+
+    return (0);
+}
+
+static int
+nrf52_adc_sample(struct adc_dev *dev)
+{
+    nrf_drv_saadc_sample();
+
+    return (0);
+}
+
+/**
+ * Callback to initialize an adc_dev structure from the os device
+ * initialization callback.  This sets up a nrf52_adc_device(), so
+ * that subsequent lookups to this device allow us to manipulate it.
+ */
+int
+nrf52_adc_dev_init(struct os_dev *odev)
+{
+    struct adc_dev *dev;
+    struct adc_driver_funcs *af;
+
+    dev = (struct adc_dev *) odev;
+
+    af = &dev->ad_funcs;
+
+    af->af_config = nrf52_adc_configure;
+    af->af_sample = nrf52_adc_sample;
+
+    return (0);
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/include/adc/adc.h
----------------------------------------------------------------------
diff --git a/drivers/adc/include/adc/adc.h b/drivers/adc/include/adc/adc.h
new file mode 100644
index 0000000..01c60ea
--- /dev/null
+++ b/drivers/adc/include/adc/adc.h
@@ -0,0 +1,43 @@
+/*
+ * 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 __ADC_H__
+#define __ADC_H__
+
+#include <os/os_dev.h>
+
+struct adc_dev;
+
+typedef int (*adc_config_func_t)(struct adc_dev *dev, void *);
+typedef int (*adc_sample_func_t)(struct adc_dev *);
+
+struct adc_driver_funcs {
+    adc_config_func_t af_config;
+    adc_sample_func_t af_sample;
+};
+
+struct adc_dev {
+    struct os_dev ad_dev;
+    struct adc_driver_funcs ad_funcs;
+};
+
+#define adc_sample(__dev) ((__dev)->ad_funcs.af_sample((__dev)))
+#define adc_configure(__dev, __b) ((__dev)->ad_funcs.af_configure((__dev), 
(__b)))
+
+#endif /* __ADC_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/adc/pkg.yml b/drivers/adc/pkg.yml
new file mode 100644
index 0000000..264adca
--- /dev/null
+++ b/drivers/adc/pkg.yml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+pkg.name: drivers/adc
+pkg.description: ADC driver interfaces
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+pkg.deps.TEST:
+   - hw/hal
+   - libs/testutil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/drivers/adc/src/adc.c
----------------------------------------------------------------------
diff --git a/drivers/adc/src/adc.c b/drivers/adc/src/adc.c
new file mode 100644
index 0000000..5198538
--- /dev/null
+++ b/drivers/adc/src/adc.c
@@ -0,0 +1,22 @@
+/*
+ * 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 <adc/adc.h>
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_adc.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_adc.h b/hw/hal/include/hal/hal_adc.h
deleted file mode 100644
index 84b16d5..0000000
--- a/hw/hal/include/hal/hal_adc.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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 H_HAL_ADC_
-#define H_HAL_ADC_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* for the pin descriptor enum */
-#include <bsp/bsp_sysid.h>
-
-/* This is the device for an ADC. The application using the ADC device
- * does not need to know the definition of this device and can operate
- * with a pointer to this device.  you can get/build device pointers in the
- * BSP
- */
-struct hal_adc;
-
-/* initialize the ADC on the corresponding BSP Pin. Returns a pointer
- * to the adc object to use for the methods below. Returns NULL on
- * error
- */
- struct hal_adc *hal_adc_init(enum system_device_id sysid);
-
-/* read the ADC corresponding to sysid in your system.  Returns
- * the  adc value read or negative on error, See
- * hal_adc_get_resolution to check the range of the return value
- */
-int hal_adc_read(struct hal_adc *padc);
-
-/* returns the number of bit of resolution in this ADC.
- * For example if the system has an 8-bit ADC reporting
- * values from 0= to 255 (2^8-1), this function would return
- * the value 8. returns negative or zero on error
- */
-int hal_adc_get_bits(struct hal_adc *padc);
-
-/* Returns the positive reference voltage for a maximum ADC reading.
- * This API assumes the negative reference voltage is zero volt.
- * Returns negative or zero on error.
- */
-int hal_adc_get_ref_mv(struct hal_adc *padc);
-
-/* Converts and ADC value to millivolts. This is a helper function
- * but does call the ADC to get the reference voltage and
- * resolution
- */
-int hal_adc_to_mv(struct hal_adc *padc, int val);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HAL_ADC_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_adc_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_adc_int.h b/hw/hal/include/hal/hal_adc_int.h
deleted file mode 100644
index 109bb0a..0000000
--- a/hw/hal/include/hal/hal_adc_int.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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_ADC_INT_H
-#define HAL_ADC_INT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <inttypes.h>
-#include <bsp/bsp_sysid.h>
-
-
-struct hal_adc;
-
-/* These functions make up the driver API for ADC devices.  All
- * ADC devices with Mynewt support implement this interface
- */
-struct hal_adc_funcs {
-    int (*hadc_read)            (struct hal_adc *padc);
-    int (*hadc_get_bits)         (struct hal_adc *padc);
-    int (*hadc_get_ref_mv)       (struct hal_adc *padc);
-};
-
-/* This is the internal device representation for a hal_adc 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 adc driver you can use
- *
- * struct my_adc_driver {
- *     struct hal_adc_s parent;
- *     int              my_stuff 1;
- *     char            *mybuff;
- * };
- *
- * See the native MCU and BSP for examples
- */
-struct hal_adc {
-    const struct hal_adc_funcs  *driver_api;
-};
-
-/* The  BSP must implement this factory to get devices for the
- * application.  */
-extern struct hal_adc *
-bsp_get_hal_adc(enum system_device_id sysid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HAL_ADC_INT_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_dac.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_dac.h b/hw/hal/include/hal/hal_dac.h
deleted file mode 100644
index 93eded4..0000000
--- a/hw/hal/include/hal/hal_dac.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 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_DAC_H_
-#define HAL_DAC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* for the pin descriptor enum */
-#include <bsp/bsp_sysid.h>
-
-/* This is the device for a Digital to Analog Converter (DAC).
- * The application using the DAC device
- * does not need to know the definition of this device and can operate
- * with a pointer to this device.  you can get/build device pointers in the
- * BSP
- *
- * NOTE: You can also use PWM devices to simulate analog output.
- * These are defined in hal_pwm.h
- */
-struct hal_dac;
-
-/* initialize the DAC on the corresponding BSP device. Returns a pointer
- * to the DAC object to use for the methods below. Returns NULL on
- * error
- */
-struct hal_dac *
-hal_dac_init(enum system_device_id sysid);
-
-/*
- * write the DAC corresponding to sysid in your system
- * and enables the DAC.  Return 0 on success negative on failures. If you
- * write a value larger than the DAC size, it will get truncated to the
- * maximum DAC value but the write will succeed.
- */
-int
-hal_dac_write(struct hal_dac *pdac, int val);
-
-/*
- * Gets the current value that is output on the DAC .
- * Return the current value on success negative on failures.
- */
-int
-hal_dac_get_current(struct hal_dac *pdac);
-
-/*
- * Returns the number of bit of resolution in this DAC.
- * For example if the system has an 8-bit DAC reporting
- * values from 0= to 255 (2^8-1), this function would return
- * the value 8. returns negative or zero on error */
-int
-hal_dac_get_bits(struct hal_dac *pdac);
-
-/*
- * Returns the positive reference voltage for a maximum DAC reading.
- * This API assumes the negative reference voltage is zero volt.
- * Returns negative or zero on error.
- */
-int
-hal_dac_get_ref_mv(struct hal_dac *pdac);
-
-/* turns the DAC off.  Re-enable with hal_dac_write */
-int
-hal_dac_disable(struct hal_dac *pdac);
-
-
-/* Converts a value in millivolts to a DAC value for this DAC */
-int
-hal_dac_to_val(struct hal_dac *pdac, int mvolts);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HAL_DAC_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_dac_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_dac_int.h b/hw/hal/include/hal/hal_dac_int.h
deleted file mode 100644
index 2bb01cd..0000000
--- a/hw/hal/include/hal/hal_dac_int.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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 H_HAL_DAC_INT_
-#define H_HAL_DAC_INT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <bsp/bsp_sysid.h>
-
-
-struct hal_dac;
-
-/* These functions make up the driver API for DAC devices.  All
- * DAC devices with Mynewt support implement this interface
- */
-struct hal_dac_funcs {
-    int (*hdac_write)            (struct hal_dac *pdac, int val);
-    int (*hdac_current)          (struct hal_dac *pdac);
-    int (*hdac_disable)          (struct hal_dac *pdac);
-    int (*hdac_get_bits)         (struct hal_dac *pdac);
-    int (*hdac_get_ref_mv)       (struct hal_dac *pdac);
-};
-
-/* This is the internal device representation for a hal_dac 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 dac driver you can use
- *
- * struct my_dac_driver {
- *     struct hal_dac   parent;
- *     int              my_stuff 1;
- *     char            *mybuff;
- * };
- *
- * See the native MCU and BSP for examples
- */
-struct hal_dac {
-    const struct hal_dac_funcs  *driver_api;
-};
-
-/* The  BSP must implement this factory to get devices for the
- * application.
- */
-extern struct hal_dac *
-bsp_get_hal_dac(enum system_device_id sysid);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* HAL_DAC_INT_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_i2c.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_i2c.h b/hw/hal/include/hal/hal_i2c.h
index a1361cd..876e287 100644
--- a/hw/hal/include/hal/hal_i2c.h
+++ b/hw/hal/include/hal/hal_i2c.h
@@ -64,11 +64,10 @@ struct hal_i2c_master_data {
     uint8_t *buffer;    /* buffer space to hold the transmit or receive */
 };
 
-/* Initialize a new i2c device with the given system id.
+/* Initialize a new i2c device with the I2C number.
  * Returns a pointer to the i2c device or NULL on error
  */
-struct hal_i2c*
-hal_i2c_init(enum system_device_id sysid);
+struct hal_i2c *hal_i2c_init(uint8_t i2c_num);
 
 /* Sends a start condition and writes <len> bytes of data on the i2c.
  * This API assumes that you have already called hal_i2c_master_begin
@@ -79,7 +78,7 @@ hal_i2c_init(enum system_device_id sysid);
  * Returns 0 on success, negative on failure
  */
 int
-hal_i2c_master_write(struct hal_i2c*, struct hal_i2c_master_data *pdata);
+hal_i2c_master_write(struct hal_i2c *, struct hal_i2c_master_data *pdata);
 
 /* Sends a start condition and reads <len> bytes of data on the i2c.
  * This API assumes that you have already called hal_i2c_master_begin
@@ -90,20 +89,20 @@ hal_i2c_master_write(struct hal_i2c*, struct 
hal_i2c_master_data *pdata);
  * Returns 0 on success, negative on failure
  */
 int
-hal_i2c_master_read(struct hal_i2c*, struct hal_i2c_master_data *pdata);
+hal_i2c_master_read(struct hal_i2c *, struct hal_i2c_master_data *pdata);
 
 /*
  * Starts an I2C transaction with the driver. This API does not send
  * anything over the bus itself
  */
 int
-hal_i2c_master_begin(struct hal_i2c*);
+hal_i2c_master_begin(struct hal_i2c *);
 
 /* issues a stop condition on the bus and ends the I2C transaction.
  * You must call i2c_master_end for every hal_i2c_master_begin
  * API call that succeeds  */
 int
-hal_i2c_master_end(struct hal_i2c*);
+hal_i2c_master_end(struct hal_i2c *);
 
 /* Probes the i2c bus for a device with this address.  THIS API
  * issues a start condition, probes the address using a read
@@ -111,7 +110,7 @@ hal_i2c_master_end(struct hal_i2c*);
  * hal_i2c_master_begin/end with this method
  */
 int
-hal_i2c_master_probe(struct hal_i2c*, uint8_t address);
+hal_i2c_master_probe(struct hal_i2c *, uint8_t address);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_i2c_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_i2c_int.h b/hw/hal/include/hal/hal_i2c_int.h
deleted file mode 100644
index 13e6e5f..0000000
--- a/hw/hal/include/hal/hal_i2c_int.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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 H_HAL_I2C_INT_
-#define H_HAL_I2C_INT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <hal/hal_i2c.h>
-#include <inttypes.h>
-
-struct hal_i2c;
-
-struct hal_i2c_funcs {
-    int (*hi2cm_write_data) (struct hal_i2c *pi2c, struct hal_i2c_master_data 
*ppkt);
-    int (*hi2cm_read_data)  (struct hal_i2c *pi2c, struct hal_i2c_master_data 
*ppkt);
-    int (*hi2cm_probe)      (struct hal_i2c *pi2c, uint8_t address);
-    int (*hi2cm_start)      (struct hal_i2c *pi2c);
-    int (*hi2cm_stop)       (struct hal_i2c *pi2c);
-};
-
-struct hal_i2c {
-    const struct hal_i2c_funcs *driver_api;
-};
-
-struct hal_i2c *
-bsp_get_hal_i2c_driver(enum system_device_id sysid);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HAL_I2C_INT_ */
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_pwm.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_pwm.h b/hw/hal/include/hal/hal_pwm.h
deleted file mode 100644
index 6deb1e7..0000000
--- a/hw/hal/include/hal/hal_pwm.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * 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 H_HAL_HAL_PWM_
-#define H_HAL_HAL_PWM_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <inttypes.h>
-#include <bsp/bsp_sysid.h>
-
-/* This is an abstract hardware API to Pulse Width Modulators.
- * A Pulse width module produces an output pulse stream with
- * a specified period, and duty cycle.
- */
-struct hal_pwm;
-
-/* Initialize a new PWM device with the given system id.
- * Returns negative on error, 0 on success.
- */
-struct hal_pwm*
-hal_pwm_init(enum system_device_id sysid);
-
-/* gets the underlying clock driving the PWM output. Return value
- * is in Hz. Returns negative on error
- */
-int
-hal_pwm_get_source_clock_freq(struct hal_pwm *ppwm);
-
-/* gets the resolution of the PWM in bits.  An N-bit PWM can have
- * on values between 0 and 2^bits - 1. Returns negative on error
- */
-int
-hal_pwm_get_resolution_bits(struct hal_pwm *ppwm);
-
-/* turns off the PWM channel */
-int
-hal_pwm_disable(struct hal_pwm *ppwm);
-
-/* enables the PWM with duty cycle specified. This duty cycle is
- * a fractional duty cycle where 0 == off, 65535=on, and
- * any value in between is on for fraction clocks and off
- * for 65535-fraction clocks.
- */
-int
-hal_pwm_enable_duty_cycle(struct hal_pwm *ppwm, uint16_t fraction);
-
-/*
- * This frequency must be between 1/2 the clock frequency and
- * the clock divided by the resolution. NOTE: This may affect
- * other PWM channels.
- */
-int
-hal_pwm_set_frequency(struct hal_pwm *ppwm, uint32_t freq_hz);
-
-/* NOTE: If you know the resolution and clock frequency, you can
- * compute the period of the PWM Its 2^resolution/clock_freq
- */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* H_HAL_HAL_PWM_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/include/hal/hal_pwm_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_pwm_int.h b/hw/hal/include/hal/hal_pwm_int.h
deleted file mode 100644
index b081da1..0000000
--- a/hw/hal/include/hal/hal_pwm_int.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * 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 H_HAL_PWM_INT_
-#define H_HAL_PWM_INT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <hal/hal_pwm.h>
-#include <inttypes.h>
-
-/* when you are implementing a driver for the hal_pwm. This is the interface
- * you must provide.
- */
-
-struct hal_pwm;
-
-struct hal_pwm_funcs {
-    /* the low level hal API */
-    int     (*hpwm_get_bits)        (struct hal_pwm *ppwm);
-    int     (*hpwm_get_clk)         (struct hal_pwm *ppwm);
-    int     (*hpwm_disable)         (struct hal_pwm *ppwm);
-    int     (*hpwm_ena_duty)  (struct hal_pwm *ppwm, uint16_t frac_duty);
-    int     (*hpwm_set_freq)  (struct hal_pwm *ppwm, uint32_t freq_hz);
-
-};
-
-struct hal_pwm {
-    const struct hal_pwm_funcs *driver_api;
-};
-
-struct hal_pwm *
-bsp_get_hal_pwm_driver(enum system_device_id sysid);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HAL_PWM_INT_ */
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/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
index 587812f..4ed5aa6 100644
--- a/hw/hal/include/hal/hal_spi.h
+++ b/hw/hal/include/hal/hal_spi.h
@@ -62,8 +62,7 @@ struct hal_spi_settings {
  * 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);
+struct hal_spi *hal_spi_init(uint8_t spi_num);
 
 /* configure the spi., Reutrns 0 on success, negative on error */
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/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
deleted file mode 100644
index 473e07e..0000000
--- a/hw/hal/include/hal/hal_spi_int.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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 H_HAL_SPI_INT_
-#define H_HAL_SPI_INT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <bsp/bsp_sysid.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);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_HAL_SPI_INT_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/src/hal_adc.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_adc.c b/hw/hal/src/hal_adc.c
deleted file mode 100644
index 6470ed9..0000000
--- a/hw/hal/src/hal_adc.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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 <inttypes.h>
-#include <hal/hal_adc.h>
-#include <hal/hal_adc_int.h>
-
-struct hal_adc *
-hal_adc_init(enum system_device_id pin) 
-{
-    return bsp_get_hal_adc(pin);
-}
-
-int 
-hal_adc_read(struct hal_adc *padc) 
-{
-    if (padc && padc->driver_api && padc->driver_api->hadc_read) {
-        return padc->driver_api->hadc_read(padc);
-    }
-    return -1;
-}
-
-int 
-hal_adc_get_bits(struct hal_adc *padc) 
-{
-    if (padc && padc->driver_api && padc->driver_api->hadc_get_bits) {
-        return padc->driver_api->hadc_get_bits(padc);
-    }
-    return -1;
-}
-
-int 
-hal_adc_get_ref_mv(struct hal_adc *padc) 
-{
-    if (padc && padc->driver_api && padc->driver_api->hadc_get_ref_mv) {
-        return padc->driver_api->hadc_get_ref_mv(padc);
-    }
-    return -1;
-}
-
-/* returns the ADC read value converted to mvolts or negative on error */
-int 
-hal_adc_to_mv(struct hal_adc *padc, int val) 
-{
-    int ret_val = -1;
-    
-    if (val >= 0)  {
-        int ref;
-        ref = hal_adc_get_ref_mv(padc);   
-        if (ref > 0) {
-            val *= ref;
-            ref = hal_adc_get_bits(padc);            
-            /* doubt there will be many 1 bit ADC, but this will
-             * adjust if its two bits or more */
-            if ( ref > 1) {
-                /* round */
-                val += (1 << (ref - 2));
-                ret_val = (val >> ref);                
-            } 
-        }
-    }
-    return ret_val;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/src/hal_dac.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_dac.c b/hw/hal/src/hal_dac.c
deleted file mode 100644
index c083a75..0000000
--- a/hw/hal/src/hal_dac.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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_dac.h>
-#include <hal/hal_dac_int.h>
-
-struct hal_dac *
-hal_dac_init(enum system_device_id pin) 
-{
-    return bsp_get_hal_dac(pin);
-}
-
-int 
-hal_dac_write(struct hal_dac *pdac, int val) 
-{
-    if (pdac && pdac->driver_api && pdac->driver_api->hdac_write) {
-        return pdac->driver_api->hdac_write(pdac, val);
-    }
-    return -1;
-}
-
-int 
-hal_dac_get_bits(struct hal_dac *pdac) 
-{
-    if (pdac && pdac->driver_api && pdac->driver_api->hdac_get_bits) {
-        return pdac->driver_api->hdac_get_bits(pdac);
-    }
-    return -1;
-}
-
-int 
-hal_dac_get_ref_mv(struct hal_dac *pdac) 
-{
-    if (pdac && pdac->driver_api && pdac->driver_api->hdac_get_ref_mv) {
-        return pdac->driver_api->hdac_get_ref_mv(pdac);
-    }
-    return -1;
-}
-
-/* gets the current DAC value */
-int 
-hal_dac_get_current(struct hal_dac *pdac) 
-{
-    if (pdac && pdac->driver_api && pdac->driver_api->hdac_get_ref_mv) {
-        return pdac->driver_api->hdac_current(pdac);
-    }
-    return -1;
-}
-
-/* Converts a millivolt value to the right DAC settings for this DAC.
- */
-int 
-hal_dac_to_val(struct hal_dac *pdac, int mvolts) 
-{
-    int rc = -1;
-    int bits = hal_dac_get_bits(pdac);
-    int ref = hal_dac_get_ref_mv(pdac);
-            
-    if ((bits > 0) && (ref >= 0)) 
-    {
-        /* assume that 2^N -1 is full scale. This line multiples by 2^N-1 
-         * and then rounds up */
-        rc = (mvolts << bits) - mvolts + (ref >> 1);
-        rc /= ref;
-        
-        /* don't let this exceed the DAC max */
-        if(rc >= (1 << bits)) {
-            rc = (1 << bits) - 1;
-        }
-    }
-    return rc;
-}
-
-int 
-hal_dac_disable(struct hal_dac *pdac) 
-{
-    if (pdac && pdac->driver_api && pdac->driver_api->hdac_disable) {
-        return pdac->driver_api->hdac_disable(pdac);
-    }
-    return -1;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/src/hal_i2c.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_i2c.c b/hw/hal/src/hal_i2c.c
deleted file mode 100644
index c383fe5..0000000
--- a/hw/hal/src/hal_i2c.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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>
-#include <hal/hal_i2c.h>
-#include <hal/hal_i2c_int.h>
-
-struct hal_i2c *
-hal_i2c_init(enum system_device_id sysid)
-{
-    return bsp_get_hal_i2c_driver(sysid);
-}
-
-int
-hal_i2c_master_write(struct hal_i2c *pi2c, struct hal_i2c_master_data *ppkt)
-{
-    if (pi2c && pi2c->driver_api && pi2c->driver_api->hi2cm_write_data )
-    {
-        return pi2c->driver_api->hi2cm_write_data(pi2c, ppkt);
-    }
-    return -1;
-}
-
-int
-hal_i2c_master_read(struct hal_i2c *pi2c, struct hal_i2c_master_data *ppkt)
-{
-    if (pi2c && pi2c->driver_api && pi2c->driver_api->hi2cm_read_data )
-    {
-        return pi2c->driver_api->hi2cm_read_data(pi2c, ppkt);
-    }
-    return -1;
-}
-
-int
-hal_i2c_master_probe(struct hal_i2c *pi2c, uint8_t address)
-{
-    if (pi2c && pi2c->driver_api && pi2c->driver_api->hi2cm_probe )
-    {
-        return pi2c->driver_api->hi2cm_probe(pi2c, address);
-    }
-    return -1;
-}
-
-int
-hal_i2c_master_begin(struct hal_i2c *pi2c)
-{
-    if (pi2c && pi2c->driver_api && pi2c->driver_api->hi2cm_start )
-    {
-        return pi2c->driver_api->hi2cm_start(pi2c);
-    }
-    return -1;
-}
-
-int
-hal_i2c_master_end(struct hal_i2c *pi2c)
-{
-    if (pi2c && pi2c->driver_api && pi2c->driver_api->hi2cm_stop )
-    {
-        return pi2c->driver_api->hi2cm_stop(pi2c);
-    }
-    return -1;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/src/hal_pwm.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_pwm.c b/hw/hal/src/hal_pwm.c
deleted file mode 100644
index b20b2e0..0000000
--- a/hw/hal/src/hal_pwm.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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>
-#include <hal/hal_pwm.h>
-#include <hal/hal_pwm_int.h>
-
-struct hal_pwm *
-hal_pwm_init(enum system_device_id sysid) 
-{
-    return bsp_get_hal_pwm_driver(sysid);
-}
-
-
-int
-hal_pwm_disable(struct hal_pwm *ppwm) 
-{
-    if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_disable ) 
-    {
-        return ppwm->driver_api->hpwm_disable(ppwm);
-    }
-    return -1;      
-}
-
-int
-hal_pwm_enable_duty_cycle(struct hal_pwm *ppwm, uint16_t fraction) {
-    if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_ena_duty ) 
-    {
-        return ppwm->driver_api->hpwm_ena_duty(ppwm, fraction);
-    }
-    return -1;      
-}
-
-int
-hal_pwm_set_frequency(struct hal_pwm *ppwm, uint32_t freq_hz) {
-    if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_set_freq) 
-    {
-        return ppwm->driver_api->hpwm_set_freq(ppwm, freq_hz);
-    }
-    return -1;       
-}
-
-int 
-hal_pwm_get_clock_freq(struct hal_pwm *ppwm) {
-    if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_get_clk ) 
-    {
-        return ppwm->driver_api->hpwm_get_clk(ppwm);
-    }
-    return -1;     
-}
-
-int
-hal_pwm_get_resolution_bits(struct hal_pwm *ppwm) {
-    if (ppwm && ppwm->driver_api && ppwm->driver_api->hpwm_get_bits ) 
-    {
-        return ppwm->driver_api->hpwm_get_bits(ppwm);
-    }
-    return -1;        
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/hw/hal/src/hal_spi.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_spi.c b/hw/hal/src/hal_spi.c
deleted file mode 100644
index 5b53150..0000000
--- a/hw/hal/src/hal_spi.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/libs/os/include/os/os_dev.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_dev.h b/libs/os/include/os/os_dev.h
new file mode 100644
index 0000000..7c3dc09
--- /dev/null
+++ b/libs/os/include/os/os_dev.h
@@ -0,0 +1,84 @@
+/**
+ * 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 _OS_DEV_H
+#define _OS_DEV_H
+
+#include <os/os.h>
+
+#include "os/queue.h"
+
+struct os_dev;
+
+/*
+ * Initialization order, defines when a device should be initialized
+ * by the Mynewt kernel.
+ *
+ */
+#define OS_DEV_INIT_KERNEL    (1)
+
+#define OS_DEV_INIT_F_CRITICAL (1 << 0)
+
+
+#define OS_DEV_INIT_PRIO_DEFAULT (0xff)
+
+/**
+ * Device status, so functions can ensure device is called in a
+ * consistent state.
+ */
+#define OS_DEV_STATUS_BASE    (1 << 0)
+#define OS_DEV_STATUS_INITING (1 << 1)
+#define OS_DEV_STATUS_READY   (1 << 2)
+
+typedef int (*os_dev_init_func_t)(struct os_dev *);
+typedef int (*os_dev_open_func_t)(struct os_dev *);
+typedef int (*os_dev_close_func_t)(struct os_dev *);
+
+struct os_dev_handlers {
+    os_dev_open_func_t od_open;
+    os_dev_close_func_t od_close;
+};
+
+/*
+ * Device structure.
+ *
+ */
+struct os_dev {
+    struct os_dev_handlers od_handlers;
+    os_dev_init_func_t od_init;
+    uint8_t od_stage;
+    uint8_t od_priority;
+    uint8_t od_init_flags;
+    uint8_t od_status;
+    char *od_name;
+    STAILQ_ENTRY(os_dev) od_next;
+};
+
+#define OS_DEV_SETHANDLERS(__dev, __open, __close)          \
+    (__dev)->od_handlers.od_open = (__open);                \
+    (__dev)->od_handlers.od_close = (__close);
+
+int os_dev_create(struct os_dev *dev, char *name, uint8_t stage,
+        uint8_t priority, os_dev_init_func_t od_init);
+int os_dev_initialize_all(uint8_t stage);
+struct os_dev *os_dev_lookup(char *name);
+int os_dev_open(struct os_dev *dev);
+int os_dev_close(struct os_dev *dev);
+
+#endif /* _OS_DEV_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 90f972e..25d9d08 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -19,6 +19,7 @@
 
 #include "os/os.h"
 #include "os/queue.h"
+#include "os/os_dev.h"
 #include "os_priv.h"
 
 #include "hal/hal_os_tick.h"
@@ -122,6 +123,9 @@ os_start(void)
 {
     os_error_t err;
 
+    err = os_dev_initialize_all(OS_DEV_INIT_KERNEL);
+    assert(err == OS_OK);
+
     err = os_arch_os_start();
     assert(err == OS_OK);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93d29b84/libs/os/src/os_dev.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_dev.c b/libs/os/src/os_dev.c
new file mode 100644
index 0000000..b99b4db
--- /dev/null
+++ b/libs/os/src/os_dev.c
@@ -0,0 +1,177 @@
+/**
+ * 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 "os/os.h"
+#include "os/queue.h"
+#include "os/os_dev.h"
+
+#include <string.h>
+
+static STAILQ_HEAD(, os_dev) g_os_dev_list;
+
+static int
+os_dev_init(struct os_dev *dev, char *name, uint8_t stage,
+        uint8_t priority, os_dev_init_func_t od_init)
+{
+    dev->od_name = name;
+    dev->od_stage = stage;
+    dev->od_priority = priority;
+    /* assume these are set after the fact. */
+    dev->od_init_flags = 0;
+    dev->od_init = od_init;
+    memset(&dev->od_handlers, 0, sizeof(dev->od_handlers));
+
+    return (0);
+}
+
+/**
+ * Add this device to the kernel.  This function adds the
+ * device to the OS
+ */
+static int
+os_dev_add(struct os_dev *dev)
+{
+    struct os_dev *cur_dev;
+
+    /* If no devices present, insert into head */
+    if (STAILQ_FIRST(&g_os_dev_list) == NULL) {
+        STAILQ_INSERT_HEAD(&g_os_dev_list, dev, od_next);
+        return (0);
+    }
+
+    /* Add devices to the list, sorted first by stage, then by
+     * priority.
+     */
+    cur_dev = NULL;
+    STAILQ_FOREACH(cur_dev, &g_os_dev_list, od_next) {
+        if (cur_dev->od_stage > dev->od_stage) {
+            continue;
+        }
+
+        if (dev->od_priority >= cur_dev->od_priority) {
+            break;
+        }
+    }
+
+    if (cur_dev) {
+        STAILQ_INSERT_AFTER(&g_os_dev_list, cur_dev, dev, od_next);
+    } else {
+        STAILQ_INSERT_TAIL(&g_os_dev_list, dev, od_next);
+    }
+
+    return (0);
+}
+
+int
+os_dev_create(struct os_dev *dev, char *name, uint8_t stage,
+        uint8_t priority, os_dev_init_func_t od_init)
+{
+    int rc;
+
+    rc = os_dev_init(dev, name, stage, priority, od_init);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = os_dev_add(dev);
+    if (rc != 0) {
+        goto err;
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+
+int
+os_dev_initialize_all(uint8_t stage)
+{
+    struct os_dev *dev;
+    int rc;
+
+    STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
+        if (dev->od_stage == stage) {
+            rc = dev->od_init(dev);
+            if (dev->od_init_flags & OS_DEV_INIT_F_CRITICAL &&
+                    rc != 0) {
+                goto err;
+            }
+        }
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+struct os_dev *
+os_dev_lookup(char *name)
+{
+    struct os_dev *dev;
+
+    dev = NULL;
+    STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
+        if (!strcmp(dev->od_name, name)) {
+            break;
+        }
+    }
+    return (dev);
+}
+
+
+int
+os_dev_open(struct os_dev *dev)
+{
+    int rc;
+
+    /* Device is not ready to be opened. */
+    if ((dev->od_status & OS_DEV_STATUS_READY) == 0) {
+        return (OS_EINVAL);
+    }
+
+    if (dev->od_handlers.od_open) {
+        rc = dev->od_handlers.od_open(dev);
+        if (rc != 0) {
+            goto err;
+        }
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+int
+os_dev_close(struct os_dev *dev)
+{
+    int rc;
+
+    if (dev->od_handlers.od_close) {
+        rc = dev->od_handlers.od_close(dev);
+        if (rc != 0) {
+            goto err;
+        }
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+

Reply via email to