Example #1
0
void ffi_init() {
    mp_obj_t m = mp_obj_new_module(QSTR_FROM_STR_STATIC("ffi"));
    rt_store_attr(m, MP_QSTR_open, (mp_obj_t)&mod_ffi_open_obj);
    rt_store_attr(m, QSTR_FROM_STR_STATIC("callback"), (mp_obj_t)&mod_ffi_callback_obj);
    // there would be as_bytes, but bytes currently is value, not reference type!
    rt_store_attr(m, QSTR_FROM_STR_STATIC("as_bytearray"), (mp_obj_t)&mod_ffi_as_bytearray_obj);
}
Example #2
0
void audio_init(void) {
    // DAC peripheral clock
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

    // DAC channel 2 (DAC_OUT2 = PA.5) configuration
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // DAC channel2 Configuration
    DAC_InitTypeDef DAC_InitStructure;
    DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
    DAC_Init(DAC_Channel_2, &DAC_InitStructure);

    // Enable DAC Channel2
    DAC_Cmd(DAC_Channel_2, ENABLE);

    // from now on use DAC_SetChannel2Data to trigger a conversion

    sample_buf_in = 0;
    sample_buf_out = 0;
    // enable interrupt

    // Python interface
    mp_obj_t m = mp_obj_new_module(qstr_from_str_static("audio"));
    rt_store_attr(m, qstr_from_str_static("dac"), rt_make_function_n(1, pyb_audio_dac));
    rt_store_attr(m, qstr_from_str_static("is_full"), rt_make_function_n(0, pyb_audio_is_full));
    rt_store_attr(m, qstr_from_str_static("fill"), rt_make_function_n(1, pyb_audio_fill));
    rt_store_name(qstr_from_str_static("audio"), m);
}
Example #3
0
void file_init() {
    rt_store_name(MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj);

    mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys);
    rt_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO));
    rt_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO));
    rt_store_attr(m_sys, MP_QSTR_stderr, fdfile_new(STDERR_FILENO));
}
Example #4
0
void timer_init(void) {
    timer_py_callback = mp_const_none;

    // TIM6 clock enable
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);

    // Compute the prescaler value so TIM6 runs at 20kHz
    uint16_t PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 20000) - 1;

    // Time base configuration
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    TIM_TimeBaseStructure.TIM_Period = 20000; // timer cycles at 1Hz
    TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0; // unused for TIM6
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // unused for TIM6
    TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

    // enable perhipheral preload register
    TIM_ARRPreloadConfig(TIM6, ENABLE);

    // enable interrupt when counter overflows
    TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);

    // set up interrupt
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = TIM6_DAC_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0f; // lowest priority
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0f; // lowest priority
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // TIM6 enable counter
    TIM_Cmd(TIM6, ENABLE);

    // Python interface
    mp_obj_t m = mp_obj_new_module(qstr_from_str_static("timer"));
    rt_store_attr(m, qstr_from_str_static("callback"), rt_make_function_n(1, timer_py_set_callback));
    rt_store_attr(m, qstr_from_str_static("period"), rt_make_function_n(1, timer_py_set_period));
    rt_store_attr(m, qstr_from_str_static("prescaler"), rt_make_function_n(1, timer_py_set_prescaler));
    rt_store_attr(m, qstr_from_str_static("value"), rt_make_function_n(0, timer_py_get_value));
    rt_store_name(qstr_from_str_static("timer"), m);
}
Example #5
0
void rawsocket_init() {
    mp_obj_t m = mp_obj_new_module(MP_QSTR_rawsocket);
    rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)&rawsocket_type);
#if MICROPY_SOCKET_EXTRA
    rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
    rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
    rt_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj);
    rt_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj);
#endif
    rt_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj);
    for (struct sym_entry *p = constants; p->sym != NULL; p++) {
        rt_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val));
    }
}