void file_buffer_on(FIL *fp) { file_buffer_offset = f_tell(fp) % 4; file_buffer_pointer = fb_alloc_all(&file_buffer_size) + file_buffer_offset; if (!file_buffer_size) { nlr_raise(mp_obj_new_exception_msg(&mp_type_MemoryError, "No memory!")); } file_buffer_size -= file_buffer_offset; file_buffer_index = 0; if (fp->flag & FA_READ) { uint32_t file_remaining = f_size(fp) - f_tell(fp); uint32_t can_do = FF_MIN(file_buffer_size, file_remaining); UINT bytes; FRESULT res = f_read(fp, file_buffer_pointer, can_do, &bytes); if (res != FR_OK) ff_fail(fp, res); if (bytes != can_do) ff_read_fail(fp); } }
// returns null pointer without error if returned size==0 void *fb_alloc0_all(uint32_t *size) { void *mem = fb_alloc_all(size); memset(mem, 0, *size); // does nothing if size is zero. return mem; }