Error as described in MBs email to MS

Dependencies:   SDFileSystem app epson mbed msp430 pl tests

Committer:
marcbax
Date:
Thu Jan 11 14:12:00 2018 +0000
Revision:
1:5874c1a074a7
Parent:
0:c643d398cdb6
Version 180111a with error as reported to Mark Symonds

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcbax 0:c643d398cdb6 1 /*
marcbax 0:c643d398cdb6 2 Plastic Logic EPD project on MSP430
marcbax 0:c643d398cdb6 3
marcbax 0:c643d398cdb6 4 Copyright (C) 2013 Plastic Logic Limited
marcbax 0:c643d398cdb6 5
marcbax 0:c643d398cdb6 6 This program is free software: you can redistribute it and/or modify
marcbax 0:c643d398cdb6 7 it under the terms of the GNU General Public License as published by
marcbax 0:c643d398cdb6 8 the Free Software Foundation, either version 3 of the License, or
marcbax 0:c643d398cdb6 9 (at your option) any later version.
marcbax 0:c643d398cdb6 10
marcbax 0:c643d398cdb6 11 This program is distributed in the hope that it will be useful,
marcbax 0:c643d398cdb6 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
marcbax 0:c643d398cdb6 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
marcbax 0:c643d398cdb6 14 GNU General Public License for more details.
marcbax 0:c643d398cdb6 15
marcbax 0:c643d398cdb6 16 You should have received a copy of the GNU General Public License
marcbax 0:c643d398cdb6 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
marcbax 0:c643d398cdb6 18 */
marcbax 0:c643d398cdb6 19 /*
marcbax 0:c643d398cdb6 20 * vcom.c -- VCOM Calculation support
marcbax 0:c643d398cdb6 21 *
marcbax 0:c643d398cdb6 22 * Authors: Nick Terry <nick.terry@plasticlogic.com>
marcbax 0:c643d398cdb6 23 *
marcbax 0:c643d398cdb6 24 */
marcbax 0:c643d398cdb6 25
marcbax 0:c643d398cdb6 26 #include "assert.h"
marcbax 0:c643d398cdb6 27 #include "vcom.h"
marcbax 0:c643d398cdb6 28 #include <stdlib.h>
marcbax 0:c643d398cdb6 29
marcbax 0:c643d398cdb6 30 #define LOG_TAG "vcom"
marcbax 0:c643d398cdb6 31 #include "utils.h"
marcbax 0:c643d398cdb6 32
marcbax 0:c643d398cdb6 33 void vcom_init(struct vcom_cal *v, const struct pl_hw_vcom_info *c)
marcbax 0:c643d398cdb6 34 {
marcbax 0:c643d398cdb6 35 assert(v != NULL);
marcbax 0:c643d398cdb6 36 assert(c != NULL);
marcbax 0:c643d398cdb6 37
marcbax 0:c643d398cdb6 38 v->dac_dx = c->dac_x2 - c->dac_x1;
marcbax 0:c643d398cdb6 39 v->dac_dy = c->dac_y2 - c->dac_y1;
marcbax 0:c643d398cdb6 40 v->dac_offset = c->dac_y1 -
marcbax 0:c643d398cdb6 41 DIV_ROUND_CLOSEST((c->dac_x1 * v->dac_dy), v->dac_dx);
marcbax 0:c643d398cdb6 42 v->swing = c->vgpos_mv - c->vgneg_mv;
marcbax 0:c643d398cdb6 43 v->swing_ideal = c->swing_ideal;
marcbax 0:c643d398cdb6 44 v->dac_step_mv = DIV_ROUND_CLOSEST(v->dac_dy, v->dac_dx);
marcbax 0:c643d398cdb6 45 }
marcbax 0:c643d398cdb6 46
marcbax 0:c643d398cdb6 47 int vcom_calculate(const struct vcom_cal *v, int input_mv)
marcbax 0:c643d398cdb6 48 {
marcbax 0:c643d398cdb6 49 int32_t scaled_mv;
marcbax 0:c643d398cdb6 50 int dac_value;
marcbax 0:c643d398cdb6 51
marcbax 0:c643d398cdb6 52 assert(v != NULL);
marcbax 0:c643d398cdb6 53
marcbax 0:c643d398cdb6 54 scaled_mv = DIV_ROUND_CLOSEST(input_mv * v->swing, v->swing_ideal);
marcbax 0:c643d398cdb6 55 dac_value = DIV_ROUND_CLOSEST((scaled_mv - v->dac_offset) * v->dac_dx,
marcbax 0:c643d398cdb6 56 v->dac_dy);
marcbax 0:c643d398cdb6 57
marcbax 0:c643d398cdb6 58 LOG("input: %d, scaled: %ld, DAC reg: 0x%02X",
marcbax 0:c643d398cdb6 59 input_mv, scaled_mv, dac_value);
marcbax 0:c643d398cdb6 60
marcbax 0:c643d398cdb6 61 return dac_value;
marcbax 0:c643d398cdb6 62 }