Flotsam / mbed-modifed

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Sep 30 20:45:04 2013 +0100
Parent:
31:42176bc3c368
Child:
33:e214068ab66c
Commit message:
Synchronized with git revision e8afb9cd1deecf3a0ef2c140d38e3f2d68a2eb50

Changed in this revision

targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/PeripheralNames.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/PeripheralNames.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/adc_pinmap.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/objects.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/pwmout_api.c Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/spi_pinmap.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/PeripheralNames.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/adc_pinmap.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/objects.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/pwmout_api.c Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/spi_pinmap.h Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/objects.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/PeripheralNames.h	Mon Sep 30 20:45:04 2013 +0100
@@ -0,0 +1,65 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed 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 MBED_PERIPHERALNAMES_H
+#define MBED_PERIPHERALNAMES_H
+
+#include "cmsis.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    UART_0 = (int)LPC_UART_BASE
+} UARTName;
+
+typedef enum {
+    I2C_0 = (int)LPC_I2C_BASE
+} I2CName;
+
+typedef enum {
+    ADC0_0 = 0,
+    ADC0_1,
+    ADC0_2,
+    ADC0_3,
+    ADC0_4,
+    ADC0_5,
+    ADC0_6,
+    ADC0_7
+} ADCName;
+
+typedef enum {
+    SPI_0 = (int)LPC_SSP0_BASE,
+    SPI_1 = (int)LPC_SSP1_BASE
+} SPIName;
+
+typedef enum {
+    PWM_1 = 0,
+    PWM_2,
+    PWM_3,
+    PWM_4,
+    PWM_5
+} PWMName;
+
+#define STDIO_UART_TX     USBTX
+#define STDIO_UART_RX     USBRX
+#define STDIO_UART        UART_0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/PeripheralNames.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 MBED_PERIPHERALNAMES_H
-#define MBED_PERIPHERALNAMES_H
-
-#include "cmsis.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
-    UART_0 = (int)LPC_UART_BASE
-} UARTName;
-
-typedef enum {
-    I2C_0 = (int)LPC_I2C_BASE
-} I2CName;
-
-typedef enum {
-    ADC0_0 = 0,
-    ADC0_1,
-    ADC0_2,
-    ADC0_3,
-    ADC0_4,
-    ADC0_5,
-    ADC0_6,
-    ADC0_7
-} ADCName;
-
-typedef enum {
-    SPI_0 = (int)LPC_SSP0_BASE,
-    SPI_1 = (int)LPC_SSP1_BASE
-} SPIName;
-
-typedef enum {
-    PWM_1 = 0,
-    PWM_2,
-    PWM_3,
-    PWM_4,
-    PWM_5,
-    PWM_6,
-    PWM_7,
-    PWM_8,
-    PWM_9,
-    PWM_10,
-    PWM_11
-} PWMName;
-
-#define STDIO_UART_TX     USBTX
-#define STDIO_UART_RX     USBRX
-#define STDIO_UART        UART_0
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/adc_pinmap.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-// ADC pin mappings for LPC11CXX
-// This should be included ONLY from analogin_api.c
-
-#ifndef ADC_PINMAP_H
-#define ADC_PINMAP_H
-
-static const PinMap PinMap_ADC[] = {
-    {P0_11, ADC0_0, 2},
-    {P1_0 , ADC0_1, 2},
-    {P1_1 , ADC0_2, 2},
-    {P1_2 , ADC0_3, 2},
-    {P1_3 , ADC0_4, 2},
-    {P1_4 , ADC0_5, 1},
-    {P1_10, ADC0_6, 1},
-    {P1_11, ADC0_7, 1},
-    {NC   , NC    , 0}
-};
-
-#endif
-
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/objects.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 MBED_OBJECTS_H
-#define MBED_OBJECTS_H
-
-#include "cmsis.h"
-#include "PortNames.h"
-#include "PeripheralNames.h"
-#include "PinNames.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct gpio_irq_s {
-    uint32_t ch;
-    PinName pin;
-    __I  uint32_t *reg_mask_read;
-};
-
-struct port_s {
-    __IO uint32_t *reg_dir;
-    __IO uint32_t *reg_data;
-    PortName port;
-    uint32_t mask;
-};
-
-struct pwmout_s {
-    PWMName pwm;
-};
-
-struct serial_s {
-    LPC_UART_TypeDef *uart;
-    int index;
-};
-
-struct analogin_s {
-    ADCName adc;
-};
-
-struct i2c_s {
-    LPC_I2C_TypeDef *i2c;
-};
-
-struct spi_s {
-    LPC_SSP_TypeDef *spi;
-};
-
-struct can_s {
-    int index;
-};
-
-#include "gpio_object.h"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/pwmout_api.c	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 "pwmout_api.h"
-#include "cmsis.h"
-#include "pinmap.h"
-#include "error.h"
-
-#define TCR_CNT_EN       0x00000001
-#define TCR_RESET        0x00000002
-
-/* To have a PWM where we can change both the period and the duty cycle,
- * we need an entire timer. With the following conventions:
- *   * MR3 is used for the PWM period
- *   * MR0, MR1, MR2 are used for the duty cycle
- */
-static const PinMap PinMap_PWM[] = {
-    /* CT16B0 */
-    {P0_8 , PWM_1, 0x02},   /* MR0 */
-    {P0_9 , PWM_2, 0x02},   /* MR1 */
-    {P0_10, PWM_3, 0x03},   /* MR2 */
-
-    /* CT16B1 */
-    {P1_9 , PWM_4, 0x01},   /* MR0 */
-    {P1_10, PWM_5, 0x02},   /* MR1 */
-
-    /* CT32B0 */
-    {P1_6 , PWM_6, 0x02},   /* MR0 */
-    {P1_7 , PWM_7, 0x02},   /* MR1 */
-    {P0_1 , PWM_8, 0x02},   /* MR2 */
-
-    /* CT32B1 */
-    {P1_1 , PWM_9 ,0x03},   /* MR0 */
-    {P1_2 , PWM_10,0x03},   /* MR1 */
-    {P1_3 , PWM_11,0x03},   /* MR2 */
-
-    {NC   , NC    ,0x00}
-};
-
-typedef struct {
-    uint8_t timer;
-    uint8_t mr;
-} timer_mr;
-
-static timer_mr pwm_timer_map[11] = {
-    {0, 0}, /* CT16B0, MR0 */
-    {0, 1}, /* CT16B0, MR1 */
-    {0, 2}, /* CT16B0, MR2 */
-
-    {1, 0}, /* CT16B1, MR0 */
-    {1, 1}, /* CT16B1, MR1 */
-
-    {2, 0}, /* CT32B0, MR0 */
-    {2, 1}, /* CT32B0, MR1 */
-    {2, 2}, /* CT32B0, MR2 */
-
-    {3, 0}, /* CT32B1, MR0 */
-    {3, 1}, /* CT32B1, MR1 */
-    {3, 2}  /* CT32B1, MR2 */
-};
-
-static LPC_TMR_TypeDef *Timers[4] = {
-    LPC_TMR16B0, LPC_TMR16B1,
-    LPC_TMR32B0, LPC_TMR32B1
-};
-
-static unsigned int pwm_clock_mhz;
-
-void pwmout_init(pwmout_t* obj, PinName pin) {
-    // determine the channel
-    PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
-    if (pwm == (uint32_t)NC)
-        error("PwmOut pin mapping failed");
-    
-    obj->pwm = pwm;
-    
-    // Timer registers
-    timer_mr tid = pwm_timer_map[pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    
-    // Disable timer
-    timer->TCR = 0;
-    
-    // Power the correspondent timer
-    LPC_SYSCON->SYSAHBCLKCTRL |= 1 << (tid.timer + 7);
-    
-    /* Enable PWM function */
-    timer->PWMC = (1 << 3)|(1 << 2)|(1 << 1)|(1 << 0);
-    
-    /* Reset Functionality on MR3 controlling the PWM period */
-    timer->MCR = 1 << 10;
-    
-    pwm_clock_mhz = SystemCoreClock / 1000000;
-    
-    // default to 20ms: standard for servos, and fine for e.g. brightness control
-    pwmout_period_ms(obj, 20);
-    pwmout_write    (obj, 0);
-    
-    // Wire pinout
-    pinmap_pinout(pin, PinMap_PWM);
-}
-
-void pwmout_free(pwmout_t* obj) {
-    // [TODO]
-}
-
-void pwmout_write(pwmout_t* obj, float value) {
-    if (value < 0.0f) {
-        value = 0.0;
-    } else if (value > 1.0f) {
-        value = 1.0;
-    }
-    
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    uint32_t t_off = timer->MR3 - (uint32_t)((float)(timer->MR3) * value);
-    
-    timer->TCR = TCR_RESET;
-    timer->MR[tid.mr] = t_off;
-    timer->TCR = TCR_CNT_EN;
-}
-
-float pwmout_read(pwmout_t* obj) {
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    
-    float v = (float)(timer->MR3 - timer->MR[tid.mr]) / (float)(timer->MR3);
-    return (v > 1.0f) ? (1.0f) : (v);
-}
-
-void pwmout_period(pwmout_t* obj, float seconds) {
-    pwmout_period_us(obj, seconds * 1000000.0f);
-}
-
-void pwmout_period_ms(pwmout_t* obj, int ms) {
-    pwmout_period_us(obj, ms * 1000);
-}
-
-// Set the PWM period, keeping the duty cycle the same.
-void pwmout_period_us(pwmout_t* obj, int us) {
-    int i = 0;
-    uint32_t period_ticks = pwm_clock_mhz * us;
-    
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    uint32_t old_period_ticks = timer->MR3;
-    
-    timer->TCR = TCR_RESET;
-    timer->MR3 = period_ticks;
-    
-    // Scale the pulse width to preserve the duty ratio
-    if (old_period_ticks > 0) {
-        for (i=0; i<3; i++) {
-            uint32_t t_off = period_ticks - (uint32_t)(((uint64_t)timer->MR[i] * (uint64_t)period_ticks) / (uint64_t)old_period_ticks);
-            timer->MR[i] = t_off;
-        }
-    }
-    timer->TCR = TCR_CNT_EN;
-}
-
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
-    pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
-}
-
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
-    pwmout_pulsewidth_us(obj, ms * 1000);
-}
-
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
-    uint32_t t_on = (uint32_t)(((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000);
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    
-    timer->TCR = TCR_RESET;
-    if (t_on > timer->MR3) {
-        pwmout_period_us(obj, us);
-    }
-    uint32_t t_off = timer->MR3 - t_on;
-    timer->MR[tid.mr] = t_off;
-    timer->TCR = TCR_CNT_EN;
-}
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/spi_pinmap.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-// SPI pin mappings for LPC11CXX
-// This should be included ONLY from spi_api.c
-
-#ifndef SPI_PINMAP_H
-#define SPI_PINMAP_H
-
-static const PinMap PinMap_SPI_SCLK[] = {
-    {P0_6 , SPI_0, 0x02},
-    {P0_10, SPI_0, 0x02},
-    {P2_11, SPI_0, 0x01},
-    {P2_1 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_MOSI[] = {
-    {P0_9 , SPI_0, 0x01},
-    {P2_3 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_MISO[] = {
-    {P0_8 , SPI_0, 0x01},
-    {P2_2 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_SSEL[] = {
-    {P0_2 , SPI_0, 0x01},
-    {P2_0 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-#endif
-
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/PeripheralNames.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 MBED_PERIPHERALNAMES_H
-#define MBED_PERIPHERALNAMES_H
-
-#include "cmsis.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
-    UART_0 = (int)LPC_UART_BASE
-} UARTName;
-
-typedef enum {
-    I2C_0 = (int)LPC_I2C_BASE
-} I2CName;
-
-typedef enum {
-    ADC0_0 = 0,
-    ADC0_1,
-    ADC0_2,
-    ADC0_3,
-    ADC0_4,
-    ADC0_5,
-    ADC0_6,
-    ADC0_7
-} ADCName;
-
-typedef enum {
-    SPI_0 = (int)LPC_SSP0_BASE,
-    SPI_1 = (int)LPC_SSP1_BASE
-} SPIName;
-
-typedef enum {
-    PWM_1 = 0,
-    PWM_2,
-    PWM_3,
-    PWM_4,
-    PWM_5
-} PWMName;
-
-#define STDIO_UART_TX     USBTX
-#define STDIO_UART_RX     USBRX
-#define STDIO_UART        UART_0
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/adc_pinmap.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-// ADC pin mappings for LPC11XX
-// This should be included ONLY from analogin_api.c
-
-#ifndef ADC_PINMAP_H
-#define ADC_PINMAP_H
-
-static const PinMap PinMap_ADC[] = {
-    {P0_11, ADC0_0, 2},
-    {P1_0 , ADC0_1, 2},
-    {P1_1 , ADC0_2, 2},
-    {P1_2 , ADC0_3, 2},
-    // ADC0_4 (P1_3) should be mapped to SWDIO only
-    {P1_4 , ADC0_5, 1},
-    {P1_10, ADC0_6, 1},
-    {P1_11, ADC0_7, 1},
-    {NC   , NC    , 0}
-};
-
-#endif
-
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/objects.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 MBED_OBJECTS_H
-#define MBED_OBJECTS_H
-
-#include "cmsis.h"
-#include "PortNames.h"
-#include "PeripheralNames.h"
-#include "PinNames.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct gpio_irq_s {
-    uint32_t ch;
-    PinName pin;
-    __I  uint32_t *reg_mask_read;
-};
-
-struct port_s {
-    __IO uint32_t *reg_dir;
-    __IO uint32_t *reg_data;
-    PortName port;
-    uint32_t mask;
-};
-
-struct pwmout_s {
-    PWMName pwm;
-};
-
-struct serial_s {
-    LPC_UART_TypeDef *uart;
-    int index;
-};
-
-struct analogin_s {
-    ADCName adc;
-};
-
-struct i2c_s {
-    LPC_I2C_TypeDef *i2c;
-};
-
-struct spi_s {
-    LPC_SSP_TypeDef *spi;
-};
-
-#include "gpio_object.h"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/pwmout_api.c	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed 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 "pwmout_api.h"
-#include "cmsis.h"
-#include "pinmap.h"
-#include "error.h"
-
-#define TCR_CNT_EN       0x00000001
-#define TCR_RESET        0x00000002
-
-/* To have a PWM where we can change both the period and the duty cycle,
- * we need an entire timer. With the following conventions:
- *   * MR3 is used for the PWM period
- *   * MR0, MR1, MR2 are used for the duty cycle
- */
-static const PinMap PinMap_PWM[] = {
-    /* CT16B0 */
-    {P0_8 , PWM_1, 0x02},   /* MR0 */
-    {P0_9 , PWM_2, 0x02},   /* MR1 */
-
-    /* CT16B1 */
-    {P1_9 , PWM_3, 0x01},   /* MR0 */
-    {P1_10, PWM_4, 0x02},   /* MR1 */
-
-    /* CT32B0 */
-    {P0_1 , PWM_5, 0x02},   /* MR2 */
-
-    {NC   , NC    ,0x00}
-};
-
-typedef struct {
-    uint8_t timer;
-    uint8_t mr;
-} timer_mr;
-
-static timer_mr pwm_timer_map[5] = {
-    {0, 0}, /* CT16B0, MR0 */
-    {0, 1}, /* CT16B0, MR1 */
-
-    {1, 0}, /* CT16B1, MR0 */
-    {1, 1}, /* CT16B1, MR1 */
-
-    {2, 2}, /* CT32B0, MR2 */
-};
-
-static LPC_TMR_TypeDef *Timers[3] = {
-    LPC_TMR16B0, LPC_TMR16B1,
-    LPC_TMR32B0
-};
-
-void pwmout_init(pwmout_t* obj, PinName pin) {
-    // determine the channel
-    PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
-    if (pwm == (uint32_t)NC)
-        error("PwmOut pin mapping failed");
-    
-    obj->pwm = pwm;
-    
-    // Timer registers
-    timer_mr tid = pwm_timer_map[pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    
-    // Disable timer
-    timer->TCR = 0;
-    
-    // Power the correspondent timer
-    LPC_SYSCON->SYSAHBCLKCTRL |= 1 << (tid.timer + 7);
-    
-    /* Enable PWM function */
-    timer->PWMC = (1 << 3)|(1 << 2)|(1 << 1)|(1 << 0);
-    
-    /* Reset Functionality on MR3 controlling the PWM period */
-    timer->MCR = 1 << 10;
-    
-    if (timer == LPC_TMR16B0 || timer == LPC_TMR16B1) {
-    /* Set 16-bit timer prescaler to avoid timer expire for default 20ms */
-    /* This can be also modified by user application, but the prescaler value */
-    /* might be trade-off to timer accuracy */
-        timer->PR = 30;
-    }
-
-    // default to 20ms: standard for servos, and fine for e.g. brightness control
-    pwmout_period_ms(obj, 20);
-    pwmout_write    (obj, 0);
-    
-    // Wire pinout
-    pinmap_pinout(pin, PinMap_PWM);
-}
-
-void pwmout_free(pwmout_t* obj) {
-    // [TODO]
-}
-
-void pwmout_write(pwmout_t* obj, float value) {
-    if (value < 0.0f) {
-        value = 0.0;
-    } else if (value > 1.0f) {
-        value = 1.0;
-    }
-    
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    uint32_t t_off = timer->MR3 - (uint32_t)((float)(timer->MR3) * value);
-    
-    timer->TCR = TCR_RESET;
-    timer->MR[tid.mr] = t_off;
-    timer->TCR = TCR_CNT_EN;
-}
-
-float pwmout_read(pwmout_t* obj) {
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    
-    float v = (float)(timer->MR3 - timer->MR[tid.mr]) / (float)(timer->MR3);
-    return (v > 1.0f) ? (1.0f) : (v);
-}
-
-void pwmout_period(pwmout_t* obj, float seconds) {
-    pwmout_period_us(obj, seconds * 1000000.0f);
-}
-
-void pwmout_period_ms(pwmout_t* obj, int ms) {
-    pwmout_period_us(obj, ms * 1000);
-}
-
-// Set the PWM period, keeping the duty cycle the same.
-void pwmout_period_us(pwmout_t* obj, int us) {
-    int i = 0;
-    uint32_t period_ticks;
-    
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    uint32_t old_period_ticks = timer->MR3;
-    period_ticks = (SystemCoreClock / 1000000 * us) / (timer->PR + 1);
-
-    timer->TCR = TCR_RESET;
-    timer->MR3 = period_ticks;
-    
-    // Scale the pulse width to preserve the duty ratio
-    if (old_period_ticks > 0) {
-        for (i=0; i<3; i++) {
-            uint32_t t_off = period_ticks - (uint32_t)(((uint64_t)timer->MR[i] * (uint64_t)period_ticks) / (uint64_t)old_period_ticks);
-            timer->MR[i] = t_off;
-        }
-    }
-    timer->TCR = TCR_CNT_EN;
-}
-
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
-    pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
-}
-
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
-    pwmout_pulsewidth_us(obj, ms * 1000);
-}
-
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
-    timer_mr tid = pwm_timer_map[obj->pwm];
-    LPC_TMR_TypeDef *timer = Timers[tid.timer];
-    uint32_t t_on = (uint32_t)((((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) / (timer->PR + 1));
-    
-    timer->TCR = TCR_RESET;
-    if (t_on > timer->MR3) {
-        pwmout_period_us(obj, us);
-    }
-    uint32_t t_off = timer->MR3 - t_on;
-    timer->MR[tid.mr] = t_off;
-    timer->TCR = TCR_CNT_EN;
-}
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/spi_pinmap.h	Wed Sep 25 11:30:05 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-// SPI pin mappings for LPC11XX
-// This should be included ONLY from spi_api.c
-
-#ifndef SPI_PINMAP_H
-#define SPI_PINMAP_H
-
-static const PinMap PinMap_SPI_SCLK[] = {
-    {P0_6 , SPI_0, 0x02},
-    {P2_11, SPI_0, 0x01},
-    {P2_1 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_MOSI[] = {
-    {P0_9 , SPI_0, 0x01},
-    {P2_3 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_MISO[] = {
-    {P0_8 , SPI_0, 0x01},
-    {P2_2 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-static const PinMap PinMap_SPI_SSEL[] = {
-    {P0_2 , SPI_0, 0x01},
-    {P2_0 , SPI_1, 0x02},
-    {NC   , NC   , 0}
-};
-
-#endif
-
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c	Wed Sep 25 11:30:05 2013 +0100
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/analogin_api.c	Mon Sep 30 20:45:04 2013 +0100
@@ -18,7 +18,17 @@
 #include "pinmap.h"
 #include "error.h"
 
-#include "adc_pinmap.h"
+static const PinMap PinMap_ADC[] = {
+    {P0_11, ADC0_0, 2},
+    {P1_0 , ADC0_1, 2},
+    {P1_1 , ADC0_2, 2},
+    {P1_2 , ADC0_3, 2},
+    // {P1_3 , ADC0_4, 2}, -- should be mapped to SWDIO only
+    {P1_4 , ADC0_5, 1},
+    {P1_10, ADC0_6, 1},
+    {P1_11, ADC0_7, 1},
+    {NC   , NC    , 0}
+};
 
 #define ANALOGIN_MEDIAN_FILTER      1
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/objects.h	Mon Sep 30 20:45:04 2013 +0100
@@ -0,0 +1,74 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed 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 MBED_OBJECTS_H
+#define MBED_OBJECTS_H
+
+#include "cmsis.h"
+#include "PortNames.h"
+#include "PeripheralNames.h"
+#include "PinNames.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct gpio_irq_s {
+    uint32_t ch;
+    PinName pin;
+    __I  uint32_t *reg_mask_read;
+};
+
+struct port_s {
+    __IO uint32_t *reg_dir;
+    __IO uint32_t *reg_data;
+    PortName port;
+    uint32_t mask;
+};
+
+struct pwmout_s {
+    PWMName pwm;
+};
+
+struct serial_s {
+    LPC_UART_TypeDef *uart;
+    int index;
+};
+
+struct analogin_s {
+    ADCName adc;
+};
+
+struct i2c_s {
+    LPC_I2C_TypeDef *i2c;
+};
+
+struct spi_s {
+    LPC_SSP_TypeDef *spi;
+};
+
+#if DEVICE_CAN
+struct can_s {
+    int index;
+};
+#endif
+
+#include "gpio_object.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pwmout_api.c	Mon Sep 30 20:45:04 2013 +0100
@@ -0,0 +1,182 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed 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 "pwmout_api.h"
+#include "cmsis.h"
+#include "pinmap.h"
+#include "error.h"
+
+#define TCR_CNT_EN       0x00000001
+#define TCR_RESET        0x00000002
+
+/* To have a PWM where we can change both the period and the duty cycle,
+ * we need an entire timer. With the following conventions:
+ *   * MR3 is used for the PWM period
+ *   * MR0, MR1, MR2 are used for the duty cycle
+ */
+static const PinMap PinMap_PWM[] = {
+    /* CT16B0 */
+    {P0_8 , PWM_1, 0x02},   /* MR0 */
+    {P0_9 , PWM_2, 0x02},   /* MR1 */
+
+    /* CT16B1 */
+    {P1_9 , PWM_3, 0x01},   /* MR0 */
+    {P1_10, PWM_4, 0x02},   /* MR1 */
+
+    /* CT32B0 */
+    {P0_1 , PWM_5, 0x02},   /* MR2 */
+
+    {NC   , NC    ,0x00}
+};
+
+typedef struct {
+    uint8_t timer;
+    uint8_t mr;
+} timer_mr;
+
+static timer_mr pwm_timer_map[5] = {
+    {0, 0}, /* CT16B0, MR0 */
+    {0, 1}, /* CT16B0, MR1 */
+
+    {1, 0}, /* CT16B1, MR0 */
+    {1, 1}, /* CT16B1, MR1 */
+
+    {2, 2}, /* CT32B0, MR2 */
+};
+
+static LPC_TMR_TypeDef *Timers[3] = {
+    LPC_TMR16B0, LPC_TMR16B1,
+    LPC_TMR32B0
+};
+
+void pwmout_init(pwmout_t* obj, PinName pin) {
+    // determine the channel
+    PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
+    if (pwm == (uint32_t)NC)
+        error("PwmOut pin mapping failed");
+    
+    obj->pwm = pwm;
+    
+    // Timer registers
+    timer_mr tid = pwm_timer_map[pwm];
+    LPC_TMR_TypeDef *timer = Timers[tid.timer];
+    
+    // Disable timer
+    timer->TCR = 0;
+    
+    // Power the correspondent timer
+    LPC_SYSCON->SYSAHBCLKCTRL |= 1 << (tid.timer + 7);
+    
+    /* Enable PWM function */
+    timer->PWMC = (1 << 3)|(1 << 2)|(1 << 1)|(1 << 0);
+    
+    /* Reset Functionality on MR3 controlling the PWM period */
+    timer->MCR = 1 << 10;
+    
+    if (timer == LPC_TMR16B0 || timer == LPC_TMR16B1) {
+    /* Set 16-bit timer prescaler to avoid timer expire for default 20ms */
+    /* This can be also modified by user application, but the prescaler value */
+    /* might be trade-off to timer accuracy */
+        timer->PR = 30;
+    }
+
+    // default to 20ms: standard for servos, and fine for e.g. brightness control
+    pwmout_period_ms(obj, 20);
+    pwmout_write    (obj, 0);
+    
+    // Wire pinout
+    pinmap_pinout(pin, PinMap_PWM);
+}
+
+void pwmout_free(pwmout_t* obj) {
+    // [TODO]
+}
+
+void pwmout_write(pwmout_t* obj, float value) {
+    if (value < 0.0f) {
+        value = 0.0;
+    } else if (value > 1.0f) {
+        value = 1.0;
+    }
+    
+    timer_mr tid = pwm_timer_map[obj->pwm];
+    LPC_TMR_TypeDef *timer = Timers[tid.timer];
+    uint32_t t_off = timer->MR3 - (uint32_t)((float)(timer->MR3) * value);
+    
+    timer->TCR = TCR_RESET;
+    timer->MR[tid.mr] = t_off;
+    timer->TCR = TCR_CNT_EN;
+}
+
+float pwmout_read(pwmout_t* obj) {
+    timer_mr tid = pwm_timer_map[obj->pwm];
+    LPC_TMR_TypeDef *timer = Timers[tid.timer];
+    
+    float v = (float)(timer->MR3 - timer->MR[tid.mr]) / (float)(timer->MR3);
+    return (v > 1.0f) ? (1.0f) : (v);
+}
+
+void pwmout_period(pwmout_t* obj, float seconds) {
+    pwmout_period_us(obj, seconds * 1000000.0f);
+}
+
+void pwmout_period_ms(pwmout_t* obj, int ms) {
+    pwmout_period_us(obj, ms * 1000);
+}
+
+// Set the PWM period, keeping the duty cycle the same.
+void pwmout_period_us(pwmout_t* obj, int us) {
+    int i = 0;
+    uint32_t period_ticks;
+    
+    timer_mr tid = pwm_timer_map[obj->pwm];
+    LPC_TMR_TypeDef *timer = Timers[tid.timer];
+    uint32_t old_period_ticks = timer->MR3;
+    period_ticks = (SystemCoreClock / 1000000 * us) / (timer->PR + 1);
+
+    timer->TCR = TCR_RESET;
+    timer->MR3 = period_ticks;
+    
+    // Scale the pulse width to preserve the duty ratio
+    if (old_period_ticks > 0) {
+        for (i=0; i<3; i++) {
+            uint32_t t_off = period_ticks - (uint32_t)(((uint64_t)timer->MR[i] * (uint64_t)period_ticks) / (uint64_t)old_period_ticks);
+            timer->MR[i] = t_off;
+        }
+    }
+    timer->TCR = TCR_CNT_EN;
+}
+
+void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+    pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
+}
+
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+    pwmout_pulsewidth_us(obj, ms * 1000);
+}
+
+void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+    timer_mr tid = pwm_timer_map[obj->pwm];
+    LPC_TMR_TypeDef *timer = Timers[tid.timer];
+    uint32_t t_on = (uint32_t)((((uint64_t)SystemCoreClock * (uint64_t)us) / (uint64_t)1000000) / (timer->PR + 1));
+    
+    timer->TCR = TCR_RESET;
+    if (t_on > timer->MR3) {
+        pwmout_period_us(obj, us);
+    }
+    uint32_t t_off = timer->MR3 - t_on;
+    timer->MR[tid.mr] = t_off;
+    timer->TCR = TCR_CNT_EN;
+}
--- a/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c	Wed Sep 25 11:30:05 2013 +0100
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/spi_api.c	Mon Sep 30 20:45:04 2013 +0100
@@ -19,7 +19,31 @@
 #include "pinmap.h"
 #include "error.h"
 
-#include "spi_pinmap.h"
+static const PinMap PinMap_SPI_SCLK[] = {
+    {P0_6 , SPI_0, 0x02},
+    // {P0_10, SPI_0, 0x02}, -- should be mapped to SWCLK only
+    {P2_11, SPI_0, 0x01},
+    {P2_1 , SPI_1, 0x02},
+    {NC   , NC   , 0}
+};
+
+static const PinMap PinMap_SPI_MOSI[] = {
+    {P0_9 , SPI_0, 0x01},
+    {P2_3 , SPI_1, 0x02},
+    {NC   , NC   , 0}
+};
+
+static const PinMap PinMap_SPI_MISO[] = {
+    {P0_8 , SPI_0, 0x01},
+    {P2_2 , SPI_1, 0x02},
+    {NC   , NC   , 0}
+};
+
+static const PinMap PinMap_SPI_SSEL[] = {
+    {P0_2 , SPI_0, 0x01},
+    {P2_0 , SPI_1, 0x02},
+    {NC   , NC   , 0}
+};
 
 static inline int ssp_disable(spi_t *obj);
 static inline int ssp_enable(spi_t *obj);