Skip to content

Fix for Issue 58 — Implementation of micros() #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
9e001c4
First commit of mspgcc
robertinant Mar 24, 2012
1447c8d
Intial checking of the MSP430Uploader class
robertinant Mar 24, 2012
19397d3
Initial support for the TI MSP430 16-bit MCU. Needs lots of testing and
robertinant Mar 24, 2012
6112352
Added OS X and Linux support
Mar 25, 2012
f887959
Mac OS X tools
robertinant Mar 27, 2012
92c84fd
Fixed type-o in tools unzip command
robertinant Mar 27, 2012
7254547
Rename cores/arduino to cores/msp430
robertinant Mar 27, 2012
6ffc9b5
Rename from Arduino to Energia
robertinant Mar 27, 2012
8438934
Rename arduino to erergia for the .exe
robertinant Mar 27, 2012
df0e3f9
Fix for bug #3: Timer based UART is broken and cleanup
robertinant Mar 31, 2012
b2f8300
Enhancement #4: Relocate TimerSerial
robertinant Mar 31, 2012
034a5a6
Enhancement #2
robertinant Mar 31, 2012
c9d7112
Remove msp430 specific code from main.cpp -> wiring.c
robertinant Mar 31, 2012
7d67f01
Enhancement #5
robertinant Mar 31, 2012
75019c9
Add delayMicroseconds()
robertinant Apr 2, 2012
c87e010
Icon, About and IDE GUI
Apr 3, 2012
7ff5257
Icon, About and IDE GUI
Apr 3, 2012
7dae8af
High quality icons 512x512 for OS X
Apr 3, 2012
c67ee32
Two examples: LEDs and PUSH button
Apr 3, 2012
630afba
Serial 9600bps Example
Apr 3, 2012
1d58fc1
Changed DCO freq. selection based on CALDCO_XXMHZ_ and F_CPU in board…
robertinant Apr 3, 2012
c1867e0
Fix missing _ in check for if def check
robertinant Apr 4, 2012
be72799
Fix hardcoded SMCLK
robertinant Apr 4, 2012
0d88ec1
For Mac OS X:
robertinant Apr 5, 2012
ad2eb10
For Windows:
robertinant Apr 5, 2012
b081d5d
And for Linux:
robertinant Apr 5, 2012
3407462
Improved Icon
Apr 5, 2012
cdcf16a
Fix type-o
robertinant Apr 6, 2012
e7e73b8
initial implementation of analogWrite
robertinant Apr 7, 2012
ca5bbe8
I2C Example with TMP102 Thermometer
Apr 7, 2012
5fcc847
Specific colour for error in console
Apr 8, 2012
ed527ca
I2C_Thermometer example with int
Apr 8, 2012
d1ded76
Updated About and more compact examples
Apr 11, 2012
f8a3d84
Fix type-o in in T2A2 define
robertinant Apr 11, 2012
ee80af0
Merge branch 'master' of github.com:energia/Energia
robertinant Apr 12, 2012
bfec9ee
Added P2.x to analogWrite
robertinant Apr 12, 2012
41c58be
Fix Tsample > 30us for internal temp sensor.
robertinant Apr 12, 2012
94dda60
Analog Input - MSP430 Internal Thermometer Example
Apr 12, 2012
82b5ffa
Changes to support linux. Fixed arg passing to mspdebug. Added
RickKimball Apr 13, 2012
cc88f9e
- Fixed msp430g22231 compilation
robertinant Apr 13, 2012
89d263b
Improved example
Apr 14, 2012
816f214
Add shiftIn and shiftOut
robertinant Apr 16, 2012
607be3f
Add defines for LSBFIRST and MSBFIRST
robertinant Apr 16, 2012
0daa803
Fix for Issue #9. Complete overhaul of external interrupts
robertinant Apr 16, 2012
a353bc3
Merge branch 'master' of github.com:energia/Energia
robertinant Apr 16, 2012
9aad28b
Fix for Issue #25: Change IconImage Arduino -> Energia
robertinant Apr 17, 2012
3fc0d72
Fix for Issue #10
robertinant Apr 18, 2012
4487980
Remove #pragma message
robertinant Apr 18, 2012
0e11fe4
Add INPUT_PULLUP flavor to pinMode(...)
robertinant Apr 18, 2012
b6d995a
Merge branch 'master' of github.com:energia/Energia
robertinant Apr 18, 2012
66e20d0
Fix for Issue #26. Windows energia.exe icon
robertinant Apr 19, 2012
37884e0
Add pulseIn(...)
robertinant Apr 19, 2012
1c64403
Fix for Issue #28
robertinant Apr 23, 2012
939c0dc
Add INPUT_PULLDOWN
robertinant Apr 23, 2012
2869bb9
Add INPUT_PULLDOWN flavor to pinMode(...)
robertinant Apr 23, 2012
70e1458
Pin names based on the silkscreen
Apr 25, 2012
418ecb2
Pin names based on the silkscreen and updated examples
Apr 25, 2012
f631a41
Update links
robertinant Apr 25, 2012
3f3b080
Clean slate
robertinant Apr 25, 2012
4aa0cbb
arduino->energia
robertinant Apr 25, 2012
d3aa770
This line is required by ant on Mac OS X.
Apr 25, 2012
99ba19c
Add version number to satisfy build dependency
robertinant Apr 25, 2012
b90fdd8
Merge branch 'master' of github.com:energia/Energia
robertinant Apr 25, 2012
046e786
Set version to 0006
robertinant Apr 25, 2012
3071b06
added example for 8x8 led display
Apr 25, 2012
14083d5
Merge branch 'master' of github.com:energia/Energia
Apr 25, 2012
3a84d38
added /opt/mspgcc/bin to the path for default mspgcc location
pbrier Apr 25, 2012
93e249e
Update ISR declaration: legacy -> modern
robertinant Apr 26, 2012
c241041
Update ISR declaration: legacy -> modern
robertinant Apr 26, 2012
cd8427e
Change Basics examples to be compatible with Launchpad.
robertinant Apr 28, 2012
b1d720d
Change Digital examples (sans tone ones) to be compatible with Launch…
robertinant Apr 28, 2012
2d487eb
Updated PushButton example with INPUT_PULLUP
Apr 29, 2012
0f20786
Added buzzer and analog MIC input
pbrier May 1, 2012
016f372
Added initial SPI support for USCI and USI peripherals.
RickKimball May 2, 2012
cb50037
Added initial SPI support for USCI and USI peripherals.
RickKimball May 2, 2012
4c37da6
Remove duplicate definitions. I moved these to pins_arduino.h.
RickKimball May 3, 2012
719d70c
implemented button, removed display glitch when tone is activated
May 4, 2012
a115324
defined missing timer pins for analog out
May 6, 2012
fc644a3
Added analog frequency and resolution
May 7, 2012
1a311af
- Chanved P1.4 timer from T0A2 to NOT_ON_TIMER
robertinant May 8, 2012
e08d96b
Merge branch 'master' of github.com:energia/Energia
robertinant May 8, 2012
bd3110d
Fix for Issue #47
robertinant May 15, 2012
eab57f3
Merge pull request #48 from energia/issue_47
robertinant May 16, 2012
fa0c5c0
- New version number format
robertinant May 20, 2012
2d87e0c
Change version check to accommodate new version number schema
robertinant May 20, 2012
a67810c
Conditionally hide "Upload Using Programmer" menu for msp430
robertinant May 20, 2012
9c4339d
New locations for 430-specific examples
May 21, 2012
21a3edb
Examples Updated with GREEN_LED, RED_LED and PUSH2
May 21, 2012
0522fa4
Conditionally show Tools->Burn Bootloader
robertinant May 21, 2012
906a76a
update gcc to version 4.6.3 20120301 (mspgcc LTS 20120406)
robertinant May 21, 2012
b7562f0
update gcc to version 4.6.3 20120301 (mspgcc LTS 20120406 patched to …
robertinant May 22, 2012
d99dd19
Merge branch 'master' of https://github.com/energia/Energia
robertinant May 22, 2012
f4ae1f3
Fix for Issue #32: Line numbers incorrect in the compiler messages
robertinant May 24, 2012
b891527
INPUT_PULLUP instead of INPUT
May 25, 2012
0f09a29
Fix for analogWrite() Issue #42. Freq only 245Hz vs 490 Hz needed / d…
robertinant May 25, 2012
cfe01eb
Merge pull request #32 from energia/issue_32
robertinant May 25, 2012
c5e7cd8
Change Arduino -> Energia in GUI text strings
robertinant May 26, 2012
7cbade3
Change domain arduino.cc -> energia.cc
robertinant May 26, 2012
b6d38b7
Nokia7110_430
May 26, 2012
2be486e
Nokia7110_430 — Temperature from built-in thermometer
May 26, 2012
27fe96a
add missing binary.h include
RickKimball May 26, 2012
d91d609
Nokia7110_430 — Stability enhancement
May 26, 2012
24f7bae
Add Launchapd Serial drivers
robertinant May 27, 2012
d6612f0
Merge branch 'master' of github.com:energia/Energia
robertinant May 27, 2012
27a2a9a
Nokia7110_430 Removed
May 27, 2012
897a17b
Example removed and scrapped
May 27, 2012
fdcba3e
Implementation of micros() — Fix for issue #58
May 31, 2012
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
Prev Previous commit
Next Next commit
initial implementation of analogWrite
Only tested using Fading sketch on Launchpad LED2
  • Loading branch information
robertinant committed Apr 7, 2012
commit e7e73b817445e4d1e8d4ed151f57fbea8dfd154f
29 changes: 22 additions & 7 deletions hardware/msp430/cores/msp430/Energia.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ extern "C"{
#define P6 6
#define P7 7

#define TIMER0A 1
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4
#define TIMER2 5
#define TIMER2A 6
#define TIMER2B 7
#define T0A0 0
#define T0A1 1
#define T0A2 2
#define T1A0 3
#define T1A1 4
#define T1A2 5
#define T1A3 6
#define T1A4 7
#define T1A5 8
#define T2A0 9
#define T2A1 10
#define T2A1 11

typedef uint8_t boolean;
typedef uint8_t byte;
Expand Down Expand Up @@ -94,16 +99,26 @@ void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
uint16_t analogRead(uint8_t);
void analogWrite(uint8_t, int);
void analogReference(uint16_t);

void delay(uint32_t milliseconds);

void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);

extern const uint8_t digital_pin_to_timer[];
extern const uint8_t digital_pin_to_port[];
extern const uint8_t digital_pin_to_bit_mask[];
extern const uint16_t port_to_sel[];
extern const uint16_t port_to_sel2[];

#define digitalPinToPort(P) ( digital_pin_to_port[P] )
#define digitalPinToBitMask(P) ( digital_pin_to_bit_mask[P] )
#define digitalPinToTimer(P) ( digital_pin_to_timer[P] )
#define portDirRegister(P) ( (volatile uint16_t *)( port_to_dir[P]) )
#define portSelRegister(P) ( (volatile uint16_t *)( port_to_sel[P]) )
#define portSel2Register(P) ( (volatile uint16_t *)( port_to_sel2[P]) )
#define portOutputRegister(P) ( (volatile uint16_t *)( port_to_output[P]) )
#define portInputRegister(P) ( (volatile uint16_t *)( port_to_input[P]) )
#define digitalPinToTimer(P) ( digital_pin_to_timer[P] )
Expand Down
77 changes: 72 additions & 5 deletions hardware/msp430/cores/msp430/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,81 @@ void analogReference(uint16_t mode)
analog_reference = mode;
}

/*
* TODO: make this interrupt based so that we can wait in LPM0
*/
//TODO: Can be a lot more efficient.
// - lower clock rated / input divider to conserve Energia.
// - pin configuration logic.
//Arduino specifies ~490 Hz for analog out PWM so we follow suit.
#define PWM_PERIOD F_CPU/490
#define PWM_DUTY PWM_PERIOD / 255
void analogWrite(uint8_t pin, int val)
{
pinMode(pin, OUTPUT); // pin as output

if (val == 0)
{
digitalWrite(pin, LOW); // set pin to LOW when duty cycle is 0
// digitalWrite will take care of invalid pins
}
else if (val == 255)
{
digitalWrite(pin, HIGH); // set pin HIGH when duty cycle is 255
// digitalWrite will take care of invalid pins
}
else
{

uint8_t bit = digitalPinToBitMask(pin); // get pin bit
uint8_t port = digitalPinToPort(pin); // get pin port
volatile uint16_t *sel;
volatile uint16_t *sel2;

if (port == NOT_A_PORT) return; // pin on timer?

sel = portSelRegister(port); // get the port function select register address
*sel |= bit; // set bit in pin function select register

//TODO: Firgure out a way to determine if SEL2 needs to be set
//reg2 = portSel2Register(port); // get the port function select register address

switch(digitalPinToTimer(pin)) { // which timer and CCR?
//case: T0A0 // CCR0 used as period register
case T0A1: // Timer0 / CCR1
TA0CCR0 = PWM_PERIOD; // PWM Period
TA0CCTL1 = OUTMOD_7; // reset/set
TA0CCR1 = PWM_DUTY * val; // PWM duty cycle
TA0CTL = TASSEL_2 + MC_1; // SMCLK, up mode
break;
case T0A2: // Timer0 / CCR1
TA0CCR0 = PWM_PERIOD; // PWM Period
TA0CCTL2 = OUTMOD_7; // reset/set
TA0CCR2 = PWM_DUTY * val; // PWM duty cycle
TA0CTL = TASSEL_2 + MC_1; // SMCLK, up mode
break;
#if defined(__MSP430_HAS_T1A3__)
case T1A0:
case T1A1:
case T1A2:
#endif
#if defined(__MSP430_HAS_T2A3__)
case T2A0:
case T2A1:
case T2A2:
#endif
case NOT_ON_TIMER:
default:
if (val < 128) {
digitalWrite(pin, LOW);
} else {
digitalWrite(pin, HIGH);
}
}
}
}

uint16_t analogRead(uint8_t pin)
{

// make sure we have an ADC
// Pin has ADC functionality?

#if defined(__MSP430_HAS_ADC10__)
// 0000 A0
// 0001 A1
Expand All @@ -62,6 +128,7 @@ uint16_t analogRead(uint8_t pin)
// 0111 A7
// 1010 Internal temperature sensor

// Pin has ADC functionality?
if(pin > 7 && pin != 10)
return 0;

Expand Down
62 changes: 42 additions & 20 deletions hardware/msp430/variants/launchpad/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static const uint8_t A7 = 7;
static const uint8_t A10 = 10; // special. This is the internal temp sensor

#ifdef ARDUINO_MAIN

// +-\/-+
// VCC 1| |28 GND
// (A0) P1.0 2| |27 XIN
Expand All @@ -71,6 +70,24 @@ const uint16_t port_to_dir[] = {
#endif
};

const uint16_t port_to_sel[] = {
NOT_A_PORT,
(uint16_t) &P1SEL,
(uint16_t) &P2SEL,
#ifdef __MSP430_HAS_PORT3_R__
(uint16_t) &P3SEL,
#endif
};

const uint16_t port_to_sel2[] = {
NOT_A_PORT,
(uint16_t) &P1SEL2,
(uint16_t) &P2SEL2,
#ifdef __MSP430_HAS_PORT3_R__
(uint16_t) &P3SEL2,
#endif
};

const uint16_t port_to_input[] = {
NOT_A_PORT,
(uint16_t) &P1IN,
Expand All @@ -88,27 +105,32 @@ const uint16_t port_to_output[] = {
#endif
};

const uint8_t digital_pin_to_port[] = {
NOT_A_PIN, /* 0 */
NOT_A_PIN, /* 1 */
P1, /* 2 */
P1, /* 3 */
P1, /* 4 */
P1, /* 5 */
P1, /* 6 */
P1, /* 7 */
P2, /* 8 */
P2, /* 9 */
P2, /* 10 */
P2, /* 11 */
P2, /* 12 */
P2, /* 13 */
P1, /* 14 */
P1, /* 15 */
const uint8_t digital_pin_to_timer[] = {
NOT_ON_TIMER, /* dummy */
NOT_ON_TIMER, /* 1 - VCC */
NOT_ON_TIMER, /* 2 - P1.0 */
T0A0, /* 3 - P1.1 */
T0A1, /* 4 - P1.2 */
NOT_ON_TIMER, /* 5 - P1.3 */
//only g-series with 2 timers and comp have TA0.2 on P1.4??
#if defined(__MSP430_HAS_T1A3__) && defined(__MSP430_HAS_CAPLUS__)
T0A2, /* 6 - P1.4 */
#else
NOT_ON_TIMER, /* 6 - P1.4 */
#endif
T0A0, /* 7 - P1.5 */
NOT_ON_TIMER, /* 8 - P2.0 */
NOT_ON_TIMER, /* 9 - P2.1 */
NOT_ON_TIMER, /* 10 - P2.3 */
NOT_ON_TIMER, /* 11 - P2.4 */
NOT_ON_TIMER, /* 12 - P2.5 */
NOT_ON_TIMER, /* 13 - P2.6 */
T0A1, /* 14 - P1.6 */
NOT_ON_TIMER, /* 15 - P1.7 */
};

const uint8_t digital_pin_to_timer[] = {
NOT_A_PIN, /* 0 */
const uint8_t digital_pin_to_port[] = {
NOT_A_PIN, /* dummy */
NOT_A_PIN, /* 1 */
P1, /* 2 */
P1, /* 3 */
Expand Down