diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-22 13:41:02 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-22 13:41:02 +0000 |
commit | 684164a8cf8c2b989049d964ca7fc0419ada31ab (patch) | |
tree | 9322421223707316c600e5652a8c78312ea10342 /stmhal/rng.c | |
parent | 2fb37847a712127543c879cd4c925ac4ee3c8554 (diff) |
stmhal: Add PYBv10 config; add RNG support.
Diffstat (limited to 'stmhal/rng.c')
-rw-r--r-- | stmhal/rng.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/stmhal/rng.c b/stmhal/rng.c new file mode 100644 index 000000000..20d840a6a --- /dev/null +++ b/stmhal/rng.c @@ -0,0 +1,21 @@ +#include "stm32f4xx_hal.h" + +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "obj.h" +#include "rng.h" + +STATIC RNG_HandleTypeDef RngHandle; + +void rng_init(void) { + __RNG_CLK_ENABLE(); + RngHandle.Instance = RNG; + HAL_RNG_Init(&RngHandle); +} + +STATIC mp_obj_t pyb_rng_get(void) { + return mp_obj_new_int(HAL_RNG_GetRandomNumber(&RngHandle) >> 2); +} + +MP_DEFINE_CONST_FUN_OBJ_0(pyb_rng_get_obj, pyb_rng_get); |