Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions include/libopencm3/lpc43xx/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,43 @@ extern "C" {
#define ADC0_STAT ADC_STAT(ADC0)
#define ADC1_STAT ADC_STAT(ADC1)


/* ADC_CR Values ----------------------------------------------------------- */

#define ADC_CR_CH0 (1<<0)
#define ADC_CR_CH1 (1<<1)
#define ADC_CR_CH2 (1<<2)
#define ADC_CR_CH3 (1<<3)
#define ADC_CR_CH4 (1<<4)
#define ADC_CR_CH5 (1<<5)
#define ADC_CR_CH6 (1<<6)
#define ADC_CR_CH7 (1<<7)

#define ADC_CR_CLKDIV(x) ((x&0xff)<<8)
#define ADC_CR_BURST (1<<16)

#define ADC_CR_10BITS (0<<17)
#define ADC_CR_9BITS (1<<17)
#define ADC_CR_8BITS (2<<17)
#define ADC_CR_7BITS (3<<17)
#define ADC_CR_6BITS (4<<17)
#define ADC_CR_5BITS (5<<17)
#define ADC_CR_4BITS (6<<17)
#define ADC_CR_3BITS (7<<17)

#define ADC_CR_POWER (1<<21)

#define ADC_CR_START (1<<24)
/* missing: add other start modes */

/* ADC_GDR and ADC_DR Values */
#define ADC_DR_VREF(x) ((x>>6)&0b1111111111)
#define ADC_DR_CHN(x) ((x>>24)&0b111)
#define ADC_DR_OVERRUN(x) (((x&(1<<30))!=0))
#define ADC_DR_DONE(x) (((x&(1<<31))!=0))

uint16_t adc_get_single(uint32_t adc, uint32_t flags);

/**@}*/

#ifdef __cplusplus
Expand Down
84 changes: 84 additions & 0 deletions include/libopencm3/lpc43xx/dac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** @defgroup dac_defines DAC Defines

@brief <b>Defined Constants and Types for the LPC43xx DAC</b>

@ingroup LPC43xx_defines

@version 1.0.0

@author @htmlonly &copy; @endhtmlonly 2015

@date 09 June 2015

LGPL License Terms @ref lgpl_license
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2015
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LPC43XX_DAC_H
#define LPC43XX_DAC_H

/**@{*/

#include <libopencm3/cm3/common.h>
#include <libopencm3/lpc43xx/memorymap.h>

#ifdef __cplusplus
extern "C" {
#endif

/* --- DAC registers ------------------------------------------------------- */

/* DAC register. Holds the conversion data */
#define DAC_CR MMIO32(DAC_BASE + 0x000)

/* DAC control register */
#define DAC_CTRL MMIO32(DAC_BASE + 0x004)

/* DAC counter value register */
#define DAC_CNTVAL MMIO32(DAC_BASE + 0x008)

/* --- DAC_CR values -------------------------------------------------- */

#define DAC_CR_BIAS (1 << 16) /* Settling time */

/* --- DAC_CTRL values -------------------------------------------------- */

#define DAC_CTRL_INT_DMA_REQ (1 << 0) /* DMA request */
#define DAC_CTRL_DBLBUF_ENA (1 << 1) /* DMA double-buffering */
#define DAC_CTRL_CNT_ENA (1 << 2) /* DMA time-out */
#define DAC_CTRL_DMA_ENA (1 << 3) /* Combined DAC and DMA enable */

/* --- DAC function prototypes --------------------------------------------- */

BEGIN_DECLS

void dac_init(bool fast);

void dac_set(uint16_t v);

END_DECLS

/**@}*/

#ifdef __cplusplus
}
#endif

#endif
9 changes: 9 additions & 0 deletions include/libopencm3/lpc43xx/scu.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,15 @@ typedef enum {
SCU_CONF_EZI_EN_IN_BUFFER | \
SCU_CONF_ZIF_DIS_IN_GLITCH_FILT)

/* definitions for ENAIO */

#define SCU_ENAIO_ADCx_0 (1<<0)
#define SCU_ENAIO_ADCx_1 (1<<1)
#define SCU_ENAIO_ADCx_2 (1<<2)
#define SCU_ENAIO_ADCx_3 (1<<3)
#define SCU_ENAIO_ADCx_4 (1<<4)
#define SCU_ENAIO_ADCx_5 (1<<5)
#define SCU_ENAIO_ADCx_6 (1<<6)
BEGIN_DECLS

void scu_pinmux(scu_grp_pin_t group_pin, uint32_t scu_conf);
Expand Down
7 changes: 5 additions & 2 deletions include/libopencmsis/dispatch/irqhandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
#elif defined(EFM32GG)
# include <libopencmsis/efm32/efm32gg/irqhandlers.h>

#elif defined(LPC43XX)
# include <libopencmsis/lpc43xx/irqhandlers.h>
#elif defined(LPC43XX_M4)
# include <libopencmsis/lpc43xx/m4/irqhandlers.h>

#elif defined(LPC43XX_M0)
# include <libopencmsis/lpc43xx/m0/irqhandlers.h>

#else
# warning"no chipset defined; user interrupts are not redirected"
Expand Down
51 changes: 51 additions & 0 deletions lib/lpc43xx/adc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** @defgroup adc_file ADC

@ingroup LPC43xx

@brief <b>libopencm3 LPC43xx ADC</b>

@version 1.0.0

@author @htmlonly &copy; @endhtmlonly 2015

LGPL License Terms @ref lgpl_license
*/

/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2015
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

/**@{*/

#include <libopencm3/lpc43xx/adc.h>
#include <libopencm3/lpc43xx/ccu.h>

uint16_t adc_get_single(uint32_t adc, uint32_t flags)
{
uint32_t result;
ADC_CR(adc)=flags | ADC_CR_CLKDIV((uint8_t)(208/4.5))|ADC_CR_10BITS|ADC_CR_POWER|ADC_CR_START;

do {
result=ADC_GDR(adc);
} while( (!ADC_DR_DONE(result)) );

return ADC_DR_VREF(result);
};

/**@}*/

54 changes: 54 additions & 0 deletions lib/lpc43xx/dac.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @defgroup dac_file DAC

@ingroup LPC43xx

@brief <b>libopencm3 LPC43xx DAC</b>

@version 1.0.0

@author @htmlonly &copy; @endhtmlonly 2015

LGPL License Terms @ref lgpl_license
*/

/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2015
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

/**@{*/

#include <libopencm3/lpc43xx/dac.h>
#include <libopencm3/lpc43xx/ccu.h>

static bool dac_fast = false;

void dac_init(bool fast)
{
CCU1_CLK_APB3_DAC_CFG |= 1; /* Enable DAC Clock */
DAC_CTRL = DAC_CTRL_DMA_ENA;
dac_fast = fast;
}

void dac_set(uint16_t v)
{
DAC_CR = (v & 0x3FF) << 6 | (dac_fast ? 0 : DAC_CR_BIAS);
}


/**@}*/

2 changes: 1 addition & 1 deletion lib/lpc43xx/m4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CFLAGS = -O2 -g3 \
ARFLAGS = rcs

# LPC43xx common files for M4 / M0
OBJ_LPC43XX = gpio.o scu.o i2c.o ssp.o uart.o timer.o wwdt.o
OBJ_LPC43XX = gpio.o scu.o i2c.o ssp.o uart.o timer.o wwdt.o dac.o adc.o

#LPC43xx M4 specific file + Generic LPC43xx M4/M0 files
OBJS = $(OBJ_LPC43XX) ipc.o
Expand Down