Skip to content

Commit e90eefc

Browse files
committed
stmhal: Fix servo object; add fpclassify to math functions.
1 parent 094d450 commit e90eefc

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

stmhal/math.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <stdint.h>
2+
#include <math.h>
3+
24
typedef float float_t;
35
typedef union {
46
float f;
@@ -86,7 +88,6 @@ float erfcf(float x) { return 0.0; }
8688
float modff(float x, float *y) { return 0.0; }
8789
float frexpf(float x, int *exp) { return 0.0; }
8890
float ldexpf(float x, int exp) { return 0.0; }
89-
int __fpclassifyf(float x) { return 0; }
9091

9192
/*****************************************************************************/
9293
// from musl-0.9.15 libm.h
@@ -135,6 +136,18 @@ do { \
135136
(d) = __u.f; \
136137
} while (0)
137138

139+
/*****************************************************************************/
140+
// __fpclassifyf from musl-0.9.15
141+
142+
int __fpclassifyf(float x)
143+
{
144+
union {float f; uint32_t i;} u = {x};
145+
int e = u.i>>23 & 0xff;
146+
if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
147+
if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
148+
return FP_NORMAL;
149+
}
150+
138151
/*****************************************************************************/
139152
// scalbnf from musl-0.9.15
140153

stmhal/servo.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ typedef struct _pyb_servo_obj_t {
2727
uint16_t pulse_dest;
2828
} pyb_servo_obj_t;
2929

30-
STATIC const mp_obj_type_t servo_obj_type;
31-
3230
STATIC pyb_servo_obj_t pyb_servo_obj[PYB_SERVO_NUM];
3331

3432
void servo_init(void) {
3533
timer_tim5_init();
3634

3735
// reset servo objects
3836
for (int i = 0; i < PYB_SERVO_NUM; i++) {
39-
pyb_servo_obj[i].base.type = &servo_obj_type;
37+
pyb_servo_obj[i].base.type = &pyb_servo_type;
4038
pyb_servo_obj[i].servo_id = i + 1;
4139
pyb_servo_obj[i].time_left = 0;
4240
pyb_servo_obj[i].pulse_cur = 150; // units of 10us
@@ -149,7 +147,7 @@ STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con
149147

150148
// check servo number
151149
if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) {
152-
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id));
150+
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id + 1));
153151
}
154152

155153
// get and init servo object

0 commit comments

Comments
 (0)