Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
2abbae34
Commit
2abbae34
authored
Feb 16, 2014
by
Damien George
Browse files
stm: Rename mma -> accel.
parent
754a8dd8
Changes
6
Show whitespace changes
Inline
Side-by-side
stm/Makefile
View file @
2abbae34
...
...
@@ -55,7 +55,7 @@ SRC_C = \
servo.c
\
flash.c
\
storage.c
\
mma
.c
\
accel
.c
\
usart.c
\
usb.c
\
timer.c
\
...
...
stm/
mma
.c
→
stm/
accel
.c
View file @
2abbae34
...
...
@@ -10,11 +10,11 @@
#include "systick.h"
#include "obj.h"
#include "runtime.h"
#include "
mma
.h"
#include "
accel
.h"
#define
MMA
_ADDR (0x4c)
#define
ACCEL
_ADDR (0x4c)
void
mma
_init
(
void
)
{
void
accel
_init
(
void
)
{
RCC
->
APB1ENR
|=
RCC_APB1ENR_I2C1EN
;
// enable I2C1
//gpio_pin_init(GPIOB, 6 /* B6 is SCL */, 2 /* AF mode */, 1 /* open drain output */, 1 /* 25 MHz */, 0 /* no pull up or pull down */);
...
...
@@ -25,7 +25,7 @@ void mma_init(void) {
GPIO_InitTypeDef
GPIO_InitStructure
;
// PB5 is connected to AVDD; pull high to enable MMA device
// PB5 is connected to AVDD; pull high to enable MMA
accel
device
GPIOB
->
BSRRH
=
GPIO_Pin_5
;
// PB5 low to start with
GPIO_InitStructure
.
GPIO_Pin
=
GPIO_Pin_5
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_OUT
;
...
...
@@ -75,21 +75,21 @@ void mma_init(void) {
// set START bit in CR1 to generate a start cond!
// init the chip via I2C commands
mma
_start
(
MMA
_ADDR
,
1
);
mma
_send_byte
(
0
);
mma
_stop
();
accel
_start
(
ACCEL
_ADDR
,
1
);
accel
_send_byte
(
0
);
accel
_stop
();
/*
// read and print all 11 registers
mma
_start(
MMA
_ADDR, 1);
mma
_send_byte(0);
mma
_restart(
MMA
_ADDR, 0);
accel
_start(
ACCEL
_ADDR, 1);
accel
_send_byte(0);
accel
_restart(
ACCEL
_ADDR, 0);
for (int i = 0; i <= 0xa; i++) {
int data;
if (i == 0xa) {
data =
mma
_read_nack();
data =
accel
_read_nack();
} else {
data =
mma
_read_ack();
data =
accel
_read_ack();
}
printf(" %02x", data);
}
...
...
@@ -97,26 +97,26 @@ void mma_init(void) {
*/
// put into active mode
mma
_start
(
MMA
_ADDR
,
1
);
mma
_send_byte
(
7
);
// mode
mma
_send_byte
(
1
);
// active mode
mma
_stop
();
accel
_start
(
ACCEL
_ADDR
,
1
);
accel
_send_byte
(
7
);
// mode
accel
_send_byte
(
1
);
// active mode
accel
_stop
();
/*
// infinite loop to read values
for (;;) {
sys_tick_delay_ms(500);
mma
_start(
MMA
_ADDR, 1);
mma
_send_byte(0);
mma
_restart(
MMA
_ADDR, 0);
accel
_start(
ACCEL
_ADDR, 1);
accel
_send_byte(0);
accel
_restart(
ACCEL
_ADDR, 0);
for (int i = 0; i <= 3; i++) {
int data;
if (i == 3) {
data =
mma
_read_nack();
data =
accel
_read_nack();
printf(" %02x\n", data);
} else {
data =
mma
_read_ack() & 0x3f;
data =
accel
_read_ack() & 0x3f;
if (data & 0x20) {
data |= ~0x1f;
}
...
...
@@ -134,7 +134,7 @@ static uint32_t i2c_get_sr(void) {
return
(
sr2
<<
16
)
|
sr1
;
}
void
mma
_restart
(
uint8_t
addr
,
int
write
)
{
void
accel
_restart
(
uint8_t
addr
,
int
write
)
{
// send start condition
I2C1
->
CR1
|=
I2C_CR1_START
;
...
...
@@ -142,7 +142,7 @@ void mma_restart(uint8_t addr, int write) {
uint32_t
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00030001
)
!=
0x00030001
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_restart
\n
"
);
printf
(
"timeout in
accel
_restart
\n
"
);
return
;
}
}
...
...
@@ -154,7 +154,7 @@ void mma_restart(uint8_t addr, int write) {
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00070082
)
!=
0x00070082
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_restart write
\n
"
);
printf
(
"timeout in
accel
_restart write
\n
"
);
return
;
}
}
...
...
@@ -165,48 +165,48 @@ void mma_restart(uint8_t addr, int write) {
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00030002
)
!=
0x00030002
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_restart read
\n
"
);
printf
(
"timeout in
accel
_restart read
\n
"
);
return
;
}
}
}
}
void
mma
_start
(
uint8_t
addr
,
int
write
)
{
void
accel
_start
(
uint8_t
addr
,
int
write
)
{
// wait until I2C is not busy
uint32_t
timeout
=
1000000
;
while
(
I2C1
->
SR2
&
I2C_SR2_BUSY
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_start
\n
"
);
printf
(
"timeout in
accel
_start
\n
"
);
return
;
}
}
// do rest of start
mma
_restart
(
addr
,
write
);
accel
_restart
(
addr
,
write
);
}
void
mma
_send_byte
(
uint8_t
data
)
{
void
accel
_send_byte
(
uint8_t
data
)
{
// send byte
I2C1
->
DR
=
data
;
// wait for TRA, BUSY, MSL, TXE and BTF (byte transmitted)
uint32_t
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00070084
)
!=
0x00070084
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_send_byte
\n
"
);
printf
(
"timeout in
accel
_send_byte
\n
"
);
return
;
}
}
}
uint8_t
mma
_read_ack
(
void
)
{
uint8_t
accel
_read_ack
(
void
)
{
// enable ACK of received byte
I2C1
->
CR1
|=
I2C_CR1_ACK
;
// wait for BUSY, MSL and RXNE (byte received)
uint32_t
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00030040
)
!=
0x00030040
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_read_ack
\n
"
);
printf
(
"timeout in
accel
_read_ack
\n
"
);
break
;
}
}
...
...
@@ -215,7 +215,7 @@ uint8_t mma_read_ack(void) {
return
data
;
}
uint8_t
mma
_read_nack
(
void
)
{
uint8_t
accel
_read_nack
(
void
)
{
// disable ACK of received byte (to indicate end of receiving)
I2C1
->
CR1
&=
(
uint16_t
)
~
((
uint16_t
)
I2C_CR1_ACK
);
// last byte should apparently also generate a stop condition
...
...
@@ -224,7 +224,7 @@ uint8_t mma_read_nack(void) {
uint32_t
timeout
=
1000000
;
while
((
i2c_get_sr
()
&
0x00030040
)
!=
0x00030040
)
{
if
(
--
timeout
==
0
)
{
printf
(
"timeout in
mma
_read_nack
\n
"
);
printf
(
"timeout in
accel
_read_nack
\n
"
);
break
;
}
}
...
...
@@ -233,7 +233,7 @@ uint8_t mma_read_nack(void) {
return
data
;
}
void
mma
_stop
(
void
)
{
void
accel
_stop
(
void
)
{
// send stop condition
I2C1
->
CR1
|=
I2C_CR1_STOP
;
}
...
...
@@ -241,60 +241,60 @@ void mma_stop(void) {
/******************************************************************************/
/* Micro Python bindings */
int
mma
_buf
[
12
];
int
accel
_buf
[
12
];
mp_obj_t
pyb_
mma
_read
(
void
)
{
mp_obj_t
pyb_
accel
_read
(
void
)
{
for
(
int
i
=
0
;
i
<=
6
;
i
+=
3
)
{
mma
_buf
[
0
+
i
]
=
mma
_buf
[
0
+
i
+
3
];
mma
_buf
[
1
+
i
]
=
mma
_buf
[
1
+
i
+
3
];
mma
_buf
[
2
+
i
]
=
mma
_buf
[
2
+
i
+
3
];
accel
_buf
[
0
+
i
]
=
accel
_buf
[
0
+
i
+
3
];
accel
_buf
[
1
+
i
]
=
accel
_buf
[
1
+
i
+
3
];
accel
_buf
[
2
+
i
]
=
accel
_buf
[
2
+
i
+
3
];
}
mma
_start
(
MMA
_ADDR
,
1
);
mma
_send_byte
(
0
);
mma
_restart
(
MMA
_ADDR
,
0
);
accel
_start
(
ACCEL
_ADDR
,
1
);
accel
_send_byte
(
0
);
accel
_restart
(
ACCEL
_ADDR
,
0
);
for
(
int
i
=
0
;
i
<=
2
;
i
++
)
{
int
v
=
mma
_read_ack
()
&
0x3f
;
int
v
=
accel
_read_ack
()
&
0x3f
;
if
(
v
&
0x20
)
{
v
|=
~
0x1f
;
}
mma
_buf
[
9
+
i
]
=
v
;
accel
_buf
[
9
+
i
]
=
v
;
}
int
jolt_info
=
mma
_read_nack
();
int
jolt_info
=
accel
_read_nack
();
mp_obj_t
data
[
4
];
data
[
0
]
=
mp_obj_new_int
(
mma
_buf
[
0
]
+
mma
_buf
[
3
]
+
mma
_buf
[
6
]
+
mma
_buf
[
9
]);
data
[
1
]
=
mp_obj_new_int
(
mma
_buf
[
1
]
+
mma
_buf
[
4
]
+
mma
_buf
[
7
]
+
mma
_buf
[
10
]);
data
[
2
]
=
mp_obj_new_int
(
mma
_buf
[
2
]
+
mma
_buf
[
5
]
+
mma
_buf
[
8
]
+
mma
_buf
[
11
]);
data
[
0
]
=
mp_obj_new_int
(
accel
_buf
[
0
]
+
accel
_buf
[
3
]
+
accel
_buf
[
6
]
+
accel
_buf
[
9
]);
data
[
1
]
=
mp_obj_new_int
(
accel
_buf
[
1
]
+
accel
_buf
[
4
]
+
accel
_buf
[
7
]
+
accel
_buf
[
10
]);
data
[
2
]
=
mp_obj_new_int
(
accel
_buf
[
2
]
+
accel
_buf
[
5
]
+
accel
_buf
[
8
]
+
accel
_buf
[
11
]);
data
[
3
]
=
mp_obj_new_int
(
jolt_info
);
return
rt_build_tuple
(
4
,
data
);
}
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_
mma
_read_obj
,
pyb_
mma
_read
);
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_
accel
_read_obj
,
pyb_
accel
_read
);
mp_obj_t
pyb_
mma
_read_all
(
void
)
{
mp_obj_t
pyb_
accel
_read_all
(
void
)
{
mp_obj_t
data
[
11
];
mma
_start
(
MMA
_ADDR
,
1
);
mma
_send_byte
(
0
);
mma
_restart
(
MMA
_ADDR
,
0
);
accel
_start
(
ACCEL
_ADDR
,
1
);
accel
_send_byte
(
0
);
accel
_restart
(
ACCEL
_ADDR
,
0
);
for
(
int
i
=
0
;
i
<=
9
;
i
++
)
{
data
[
i
]
=
mp_obj_new_int
(
mma
_read_ack
());
data
[
i
]
=
mp_obj_new_int
(
accel
_read_ack
());
}
data
[
10
]
=
mp_obj_new_int
(
mma
_read_nack
());
data
[
10
]
=
mp_obj_new_int
(
accel
_read_nack
());
return
rt_build_tuple
(
11
,
data
);
}
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_
mma
_read_all_obj
,
pyb_
mma
_read_all
);
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_
accel
_read_all_obj
,
pyb_
accel
_read_all
);
mp_obj_t
pyb_
mma
_write_mode
(
mp_obj_t
o_int
,
mp_obj_t
o_mode
)
{
mma
_start
(
MMA
_ADDR
,
1
);
mma
_send_byte
(
6
);
// start at int
mma
_send_byte
(
mp_obj_get_int
(
o_int
));
mma
_send_byte
(
mp_obj_get_int
(
o_mode
));
mma
_stop
();
mp_obj_t
pyb_
accel
_write_mode
(
mp_obj_t
o_int
,
mp_obj_t
o_mode
)
{
accel
_start
(
ACCEL
_ADDR
,
1
);
accel
_send_byte
(
6
);
// start at int
accel
_send_byte
(
mp_obj_get_int
(
o_int
));
accel
_send_byte
(
mp_obj_get_int
(
o_mode
));
accel
_stop
();
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_2
(
pyb_
mma
_write_mode_obj
,
pyb_
mma
_write_mode
);
MP_DEFINE_CONST_FUN_OBJ_2
(
pyb_
accel
_write_mode_obj
,
pyb_
accel
_write_mode
);
stm/accel.h
0 → 100644
View file @
2abbae34
void
accel_init
(
void
);
void
accel_restart
(
uint8_t
addr
,
int
write
);
void
accel_start
(
uint8_t
addr
,
int
write
);
void
accel_send_byte
(
uint8_t
data
);
uint8_t
accel_read_ack
(
void
);
uint8_t
accel_read_nack
(
void
);
void
accel_stop
(
void
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_accel_read_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_accel_read_all_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_accel_write_mode_obj
);
stm/main.c
View file @
2abbae34
...
...
@@ -38,7 +38,7 @@
#include "lcd.h"
#include "storage.h"
#include "sdcard.h"
#include "
mma
.h"
#include "
accel
.h"
#include "usart.h"
#include "usb.h"
#include "timer.h"
...
...
@@ -463,9 +463,9 @@ soft_reset:
#endif
rt_store_attr
(
m
,
MP_QSTR_pwm
,
rt_make_function_n
(
2
,
pyb_pwm_set
));
#if MICROPY_HW_HAS_MMA7660
rt_store_attr
(
m
,
MP_QSTR_accel
,
(
mp_obj_t
)
&
pyb_
mma
_read_obj
);
rt_store_attr
(
m
,
MP_QSTR_
mma
_read
,
(
mp_obj_t
)
&
pyb_
mma
_read_all_obj
);
rt_store_attr
(
m
,
MP_QSTR_
mma
_mode
,
(
mp_obj_t
)
&
pyb_
mma
_write_mode_obj
);
rt_store_attr
(
m
,
MP_QSTR_accel
,
(
mp_obj_t
)
&
pyb_
accel
_read_obj
);
rt_store_attr
(
m
,
MP_QSTR_
accel
_read
,
(
mp_obj_t
)
&
pyb_
accel
_read_all_obj
);
rt_store_attr
(
m
,
MP_QSTR_
accel
_mode
,
(
mp_obj_t
)
&
pyb_
accel
_write_mode_obj
);
#endif
rt_store_attr
(
m
,
MP_QSTR_hid
,
rt_make_function_n
(
1
,
pyb_hid_send_report
));
#if MICROPY_HW_ENABLE_RTC
...
...
@@ -583,8 +583,8 @@ soft_reset:
if
(
first_soft_reset
)
{
#if MICROPY_HW_HAS_MMA7660
// MMA: init and reset address to zero
mma
_init
();
// MMA
accel
: init and reset address to zero
accel
_init
();
#endif
}
...
...
@@ -654,17 +654,17 @@ soft_reset:
#else
data
[
0
]
=
0x00
;
#endif
mma
_start
(
0x4c
/*
MMA
_ADDR */
,
1
);
mma
_send_byte
(
0
);
mma
_restart
(
0x4c
/*
MMA
_ADDR */
,
0
);
accel
_start
(
0x4c
/*
ACCEL
_ADDR */
,
1
);
accel
_send_byte
(
0
);
accel
_restart
(
0x4c
/*
ACCEL
_ADDR */
,
0
);
for
(
int
i
=
0
;
i
<=
1
;
i
++
)
{
int
v
=
mma
_read_ack
()
&
0x3f
;
int
v
=
accel
_read_ack
()
&
0x3f
;
if
(
v
&
0x20
)
{
v
|=
~
0x1f
;
}
data
[
1
+
i
]
=
v
;
}
mma
_read_nack
();
accel
_read_nack
();
usb_hid_send_report
(
data
);
sys_tick_delay_ms
(
15
);
}
...
...
stm/mma.h
deleted
100644 → 0
View file @
754a8dd8
void
mma_init
(
void
);
void
mma_restart
(
uint8_t
addr
,
int
write
);
void
mma_start
(
uint8_t
addr
,
int
write
);
void
mma_send_byte
(
uint8_t
data
);
uint8_t
mma_read_ack
(
void
);
uint8_t
mma_read_nack
(
void
);
void
mma_stop
(
void
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_mma_read_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_mma_read_all_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_mma_write_mode_obj
);
stm/qstrdefsport.h
View file @
2abbae34
...
...
@@ -15,8 +15,8 @@ Q(switch)
Q
(
servo
)
Q
(
pwm
)
Q
(
accel
)
Q
(
mma
_read
)
Q
(
mma
_mode
)
Q
(
accel
_read
)
Q
(
accel
_mode
)
Q
(
hid
)
Q
(
time
)
Q
(
rand
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment