Skip to content

Commit a6b5a3e

Browse files
committed
Bug fixes, LPC programming updates
1 parent e24e26a commit a6b5a3e

File tree

13 files changed

+604
-326
lines changed

13 files changed

+604
-326
lines changed

include/hal/I2C.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class I2C : public Periph {
2525
SETUP_WRITE_PTR_TRANSFER /*! \brief I2C transfer that only writes the pointer (no data is transferred) */ = I2C_TRANSFER_WRITE_PTR
2626
};
2727

28+
enum {
29+
MASTER /*! \brief I2C acts as master */ = I2C_ATTR_FLAG_MASTER,
30+
SLAVE /*! \brief I2C acts as slave */ = I2C_ATTR_FLAG_SLAVE,
31+
SLAVE_ACK_GENERAL_CALL /*! \brief I2C slave will ack the general call */ = I2C_ATTR_FLAG_SLAVE_ACK_GENERAL_CALL,
32+
PULLUP /*! \brief Enable internal resistor pullups where available */ = I2C_ATTR_FLAG_PULLUP
33+
};
34+
2835
/*! \details Get the I2C attributes */
2936
int get_attr(i2c_attr_t & attr);
3037
/*! \details Set the I2C attributes */
@@ -53,10 +60,11 @@ class I2C : public Periph {
5360
}
5461

5562
/*! \details Set attributes using specified bitrate and pin assignment. */
56-
int set_attr(u32 bitrate = 100000, u8 pin_assign = 0){
63+
int set_attr(u32 bitrate = 100000, u8 pin_assign = 0, u16 o_flags = MASTER){
5764
i2c_attr_t attr;
5865
attr.bitrate = bitrate;
5966
attr.pin_assign = pin_assign;
67+
attr.o_flags = o_flags;
6068
return set_attr(attr);
6169
}
6270

include/hal/Uart.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Uart : public Periph {
9696
int set_attr(int baudrate /*! Baudrate */ = 19200,
9797
int pin_assign /*! Pin assignment */ = 0,
9898
int parity /*! Parity */ = UART_PARITY_NONE,
99-
int stop /*! Number of stop bits */ = UART_ATTR_STOP_BITS_2,
99+
int stop /*! Number of stop bits */ = STOP1,
100100
int width /*! bits per character */ = 8){
101101
uart_attr_t attr;
102102
attr.baudrate = baudrate;

include/isp/Isp.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ class Isp {
1414
public:
1515
Isp(){}
1616

17-
virtual int program(const char * filename, int crystal, const char * dev, bool (*progress)(void*,int,int), void * context) = 0;
17+
/*! \details Program the device with the specified filename */
18+
virtual int program(const char * filename, int crystal, const char * dev, bool (*progress)(void*,int,int), void * context = 0) = 0;
19+
/*! \details Read the image from the device */
1820
virtual int read(const char * filename, int crystal, bool (*progress)(void*,int,int), void * context) = 0;
1921
virtual char ** getlist() = 0;
2022
virtual int copy_names(char * device, char * pio0, char * pio1) = 0;
23+
24+
/*! \details Initialize the physical layer interface */
2125
virtual int init_phy(int uart_pinassign) = 0;
26+
/*! \details De-initialize the physical layer interface */
2227
virtual int exit_phy() = 0;
28+
/*! \details Reset the target device */
2329
virtual int reset() = 0;
2430

2531
static int name_maxsize(){ return 32; }

include/isp/LpcIsp.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
#include <mcu/types.h>
77
#include "../hal/Uart.hpp"
88
#include "../hal/Pin.hpp"
9+
#include "../sys/Trace.hpp"
910
#include "Isp.hpp"
1011
#include "LpcPhy.hpp"
1112

1213
namespace isp {
1314

1415
class LpcIsp : public Isp {
1516
public:
17+
18+
/*! \details Construct an LPC ISP object using the specified UART, reset pin and isp request pin */
1619
LpcIsp(hal::Uart & uart, hal::Pin & rst, hal::Pin & ispreq) : m_phy(uart, rst, ispreq){}
1720

18-
int program(const char * filename, int crystal, const char * dev, bool (*progress)(void*,int, int), void * context);
21+
int program(const char * filename, int crystal, const char * dev, bool (*progress)(void*,int, int), void * context = 0);
1922
int read(const char * filename, int crystal, bool (*progress)(void*,int, int), void * context);
2023
char ** getlist();
2124

@@ -40,6 +43,8 @@ class LpcIsp : public Isp {
4043

4144
int write_vector_checksum(unsigned char * hex_buffer, const char * dev);
4245
int prog_shutdown();
46+
47+
sys::Trace m_trace;
4348
};
4449

4550
};

include/isp/LpcPhy.hpp

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "../hal/Uart.hpp"
77
#include "../hal/Pin.hpp"
8+
#include "../sys/Trace.hpp"
89

910
#define LPC_ISP_UNLOCK_CODE "23130"
1011

@@ -17,28 +18,31 @@ class LpcPhy {
1718
LpcPhy(hal::Uart & uart, hal::Pin & reset, hal::Pin & ispreq) : m_uart(uart), m_reset(reset), m_ispreq(ispreq){
1819
m_echo = 0;
1920
m_ram_buffer = 0x40000200;
20-
m_is_lpc177x_8x = false;
21+
m_is_return_code_newline = false;
22+
m_is_uuencode = false;
23+
m_pinassign = 0;
24+
m_max_speed = MAX_SPEED_115200;
2125
}
2226

2327

2428
int init(int pinassign);
2529
int exit();
2630
int open(int crystal);
2731
int close();
28-
int writemem(u32 loc, const void * buf, int nbyte, u32 sector);
32+
int write_memory(u32 loc, const void * buf, int nbyte, u32 sector);
2933
void set_ram_buffer(u32 addr);
30-
int readmem(u32 loc, void * buf, int nbyte);
34+
int read_memory(u32 loc, void * buf, int nbyte);
3135
int reset();
3236
int start_bootloader();
3337
int sync_bootloader(u32 crystal);
3438
int sync_bootloader_lpc177x_8x(u32 crystal);
3539
int unlock(const char * unlock_code);
36-
int echo_off();
37-
int echo_on();
38-
int wr_ram(u32 ram_dest /*! The RAM destination address--must be a word boundary */,
40+
int disable_echo();
41+
int enable_echo();
42+
int write_ram(u32 ram_dest /*! The RAM destination address--must be a word boundary */,
3943
void * src /*! A pointer to the source data */,
4044
u32 size /*! The number of bytes to write--must be a multiple of 4 */);
41-
u32 rd_mem(void * dest /*! A pointer to the destination memory */,
45+
u32 read_mem(void * dest /*! A pointer to the destination memory */,
4246
u32 src_addr /*! The source address to read--must be a word boundary */,
4347
u32 size /*! The number of bytes to read--must be a multiple of 4 */);
4448
int prep_sector(u32 start /*! The first sector to prepare */,
@@ -52,31 +56,56 @@ class LpcPhy {
5256
u32 end /*! The last sector to erase--must be >= start */);
5357
int blank_check_sector(u32 start /*! The first sector to blank check */,
5458
u32 end /*! The last sector to blank check--must be >= start */);
55-
u32 rd_part_id();
56-
u32 rd_boot_version();
57-
int memcmp(u32 addr0 /*! The beginning of the first block */,
59+
u32 read_part_id();
60+
u32 read_boot_version();
61+
int compare_memory(u32 addr0 /*! The beginning of the first block */,
5862
u32 addr1 /*! The beginning of the second block */,
5963
u32 size /*! The number of bytes to compare */);
6064

65+
void set_uuencode(bool v = true){ m_is_uuencode = v; }
66+
bool is_uuencode() const { return m_is_uuencode; }
67+
68+
void set_max_speed(u16 v){
69+
m_max_speed = v;
70+
if( m_max_speed > MAX_SPEED_9600 ){
71+
m_max_speed = MAX_SPEED_9600;
72+
}
73+
}
74+
75+
enum {
76+
MAX_SPEED_115200,
77+
MAX_SPEED_78600,
78+
MAX_SPEED_57600,
79+
MAX_SPEED_38400,
80+
MAX_SPEED_19200,
81+
MAX_SPEED_9600
82+
};
83+
6184
private:
6285
char m_echo;
6386
hal::Uart & m_uart;
6487
hal::Pin & m_reset;
6588
hal::Pin & m_ispreq;
6689
u32 m_ram_buffer;
67-
int32_t lpc_write_data(void * src, u32 size);
68-
int32_t lpc_read_data(void * dest, u32 size);
90+
int m_pinassign;
91+
bool m_is_return_code_newline;
92+
bool m_is_uuencode;
93+
u16 m_max_speed;
94+
95+
int send_command(const char * cmd, int timeout, int wait_ms = 0);
96+
s32 write_data(void * src, u32 size);
97+
s32 read_data(void * dest, u32 size);
6998
int get_line(void * buf, int nbyte, int max_wait);
70-
int lpc_rd_return_code(u16 timeout);
71-
int lpc_wait_response(const char * response, u16 timeout);
72-
int lpc_wait_ok(u16 timeout);
99+
int read_return_code(u16 timeout);
100+
int wait_response(const char * response, u16 timeout);
101+
int wait_ok(u16 timeout);
102+
73103

74-
bool m_is_lpc177x_8x;
75-
bool is_lpc177x_8x(){ return m_is_lpc177x_8x; }
76-
void set_lpc177x_8x(bool enabled = true){ m_is_lpc177x_8x = enabled; }
104+
bool is_return_code_newline(){ return m_is_return_code_newline; }
105+
void set_return_code_newline(bool enabled = true){ m_is_return_code_newline = enabled; }
77106

78-
int sendcommand(const char * cmd, int timeout, int wait_ms = 0);
79107

108+
sys::Trace m_trace;
80109
int flush();
81110

82111
};

include/sys.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace sys {};
1717
#include "sys/Sched.hpp"
1818
#include "sys/Timer.hpp"
1919
#include "sys/Time.hpp"
20-
#include "sys/Trace.hpp"
2120
#include "sys/Dbug.hpp"
2221
#include "sys/DbugStdout.hpp"
2322
#include "sys/DbugUart.hpp"
2423
#endif
2524

25+
#include "sys/Trace.hpp"
2626
#include "sys/Kernel.hpp"
2727
#include "sys/Appfs.hpp"
2828
#include "sys/Dir.hpp"

include/sys/Trace.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ class Trace : public var::String {
2626
Trace& operator=(const char * a){ var::String::operator=(a); return *this; }
2727
Trace& operator=(const var::String & a){ var::String::operator=(a); return *this; }
2828

29+
#if !defined __link
2930
inline void message() MCU_ALWAYS_INLINE { stratify_trace_event(POSIX_TRACE_MESSAGE, c_str(), size()); }
3031
inline void warning() MCU_ALWAYS_INLINE { stratify_trace_event(POSIX_TRACE_WARNING, c_str(), size()); }
3132
inline void error() MCU_ALWAYS_INLINE { stratify_trace_event(POSIX_TRACE_ERROR, c_str(), size()); }
3233
inline void critical() MCU_ALWAYS_INLINE { stratify_trace_event(POSIX_TRACE_CRITICAL, c_str(), size()); }
3334
inline void fatal() MCU_ALWAYS_INLINE { stratify_trace_event(POSIX_TRACE_FATAL, c_str(), size()); }
35+
#else
36+
inline void message(){}
37+
inline void warning(){}
38+
inline void error(){}
39+
inline void critical(){}
40+
inline void fatal(){}
41+
#endif
3442

3543
};
3644

include/ui/Button.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class Button {
3737
*/
3838
static void set_held_duration(u32 v){ m_held_duration = v; }
3939

40+
/*! \details This method returns the max held duration which will effectively disable the
41+
* reporting of button holds
42+
*
43+
*
44+
* \code
45+
* Button::set_held_duration( Button::max_held_duration() );
46+
* \endcode
47+
*/
48+
static u32 max_held_duration(){ return (u32)-1; }
49+
4050
/*! \details This method checks the state of the actuation and then returns
4151
* an Event if needed.
4252
*
@@ -50,7 +60,9 @@ class Button {
5060
*/
5161
ui::Event event();
5262

63+
/*! \details Set the event ID of the button */
5364
void set_event_id(enum ui::Event::button_id v){ m_event_id = v; }
65+
/*! \details Access the event ID of the button */
5466
enum ui::Event::button_id event_id() const { return m_event_id; }
5567

5668
/*! \details Returns the duration of the last button press.
@@ -99,7 +111,6 @@ class Button {
99111
protected:
100112

101113
virtual bool get_is_active() const = 0;
102-
103114
static u32 m_held_duration;
104115
enum ui::Event::button_id m_event_id;
105116

@@ -112,6 +123,7 @@ class Button {
112123
unsigned release_reported:1;
113124
unsigned held_reported:1;
114125
unsigned actuation_reported:1;
126+
unsigned duration_reported:1;
115127
};
116128

117129
struct button_flags m_flags;

include/ui/Element.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Element : public draw::Drawing {
2828

2929
/*! \details Returns true if element is enabled */
3030
inline bool is_enabled() const { return flag(FLAG_ENABLED); }
31+
/*! \details Enable the element */
32+
inline void set_enable(bool v = true){ set_flag(FLAG_ENABLED, v); }
3133
inline void set_enabled(bool v = true){ set_flag(FLAG_ENABLED, v); }
3234

3335
/*! \details Returns true if element is visible */

0 commit comments

Comments
 (0)